From 66b4b98abf20a4284d532f3172bfec6b17113f94 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 19 Nov 2024 06:22:07 +0000 Subject: [PATCH] Bump github.com/jedib0t/go-pretty/v6 from 6.6.1 to 6.6.2 Bumps [github.com/jedib0t/go-pretty/v6](https://github.com/jedib0t/go-pretty) from 6.6.1 to 6.6.2. - [Release notes](https://github.com/jedib0t/go-pretty/releases) - [Commits](https://github.com/jedib0t/go-pretty/compare/v6.6.1...v6.6.2) --- updated-dependencies: - dependency-name: github.com/jedib0t/go-pretty/v6 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 +- .../jedib0t/go-pretty/v6/table/style.go | 26 +- .../jedib0t/go-pretty/v6/table/table.go | 15 + vendor/modules.txt | 5 +- .../pkg/builder/controller.go | 421 ------------------ .../controller-runtime/pkg/builder/doc.go | 28 -- .../controller-runtime/pkg/builder/options.go | 156 ------- .../controller-runtime/pkg/builder/webhook.go | 256 ----------- .../pkg/conversion/conversion.go | 40 -- .../pkg/webhook/conversion/conversion.go | 343 -------------- .../pkg/webhook/conversion/decoder.go | 50 --- 12 files changed, 38 insertions(+), 1308 deletions(-) delete mode 100644 vendor/sigs.k8s.io/controller-runtime/pkg/builder/controller.go delete mode 100644 vendor/sigs.k8s.io/controller-runtime/pkg/builder/doc.go delete mode 100644 vendor/sigs.k8s.io/controller-runtime/pkg/builder/options.go delete mode 100644 vendor/sigs.k8s.io/controller-runtime/pkg/builder/webhook.go delete mode 100644 vendor/sigs.k8s.io/controller-runtime/pkg/conversion/conversion.go delete mode 100644 vendor/sigs.k8s.io/controller-runtime/pkg/webhook/conversion/conversion.go delete mode 100644 vendor/sigs.k8s.io/controller-runtime/pkg/webhook/conversion/decoder.go diff --git a/go.mod b/go.mod index 51b773dc7b..52c676d07a 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/go-logr/logr v1.4.2 github.com/golang-jwt/jwt/v4 v4.5.1 github.com/google/go-containerregistry v0.20.2 - github.com/jedib0t/go-pretty/v6 v6.6.1 + github.com/jedib0t/go-pretty/v6 v6.6.2 github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 github.com/onsi/ginkgo/v2 v2.21.0 github.com/onsi/gomega v1.35.1 diff --git a/go.sum b/go.sum index fc61ded451..f217af77c5 100644 --- a/go.sum +++ b/go.sum @@ -245,8 +245,8 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2 github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= -github.com/jedib0t/go-pretty/v6 v6.6.1 h1:iJ65Xjb680rHcikRj6DSIbzCex2huitmc7bDtxYVWyc= -github.com/jedib0t/go-pretty/v6 v6.6.1/go.mod h1:zbn98qrYlh95FIhwwsbIip0LYpwSG8SUOScs+v9/t0E= +github.com/jedib0t/go-pretty/v6 v6.6.2 h1:27bLj3nRODzaiA7tPIxy9UVWHoPspFfME9XxgwiiNsM= +github.com/jedib0t/go-pretty/v6 v6.6.2/go.mod h1:zbn98qrYlh95FIhwwsbIip0LYpwSG8SUOScs+v9/t0E= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= diff --git a/vendor/github.com/jedib0t/go-pretty/v6/table/style.go b/vendor/github.com/jedib0t/go-pretty/v6/table/style.go index 23b32b1bd6..aaed2c27fe 100644 --- a/vendor/github.com/jedib0t/go-pretty/v6/table/style.go +++ b/vendor/github.com/jedib0t/go-pretty/v6/table/style.go @@ -690,17 +690,29 @@ var ( // FormatOptions defines the text-formatting to perform on parts of the Table. type FormatOptions struct { - Direction text.Direction // (forced) BiDi direction for each Column - Footer text.Format // footer row(s) text format - Header text.Format // header row(s) text format - Row text.Format // (data) row(s) text format + Direction text.Direction // (forced) BiDi direction for each Column + Footer text.Format // default text format + FooterAlign text.Align // default horizontal align + FooterVAlign text.VAlign // default vertical align + Header text.Format // default text format + HeaderAlign text.Align // default horizontal align + HeaderVAlign text.VAlign // default vertical align + Row text.Format // default text format + RowAlign text.Align // default horizontal align + RowVAlign text.VAlign // default vertical align } // FormatOptionsDefault defines sensible formatting options. var FormatOptionsDefault = FormatOptions{ - Footer: text.FormatUpper, - Header: text.FormatUpper, - Row: text.FormatDefault, + Footer: text.FormatUpper, + FooterAlign: text.AlignDefault, + FooterVAlign: text.VAlignDefault, + Header: text.FormatUpper, + HeaderAlign: text.AlignDefault, + HeaderVAlign: text.VAlignDefault, + Row: text.FormatDefault, + RowAlign: text.AlignDefault, + RowVAlign: text.VAlignDefault, } // HTMLOptions defines the global options to control HTML rendering. diff --git a/vendor/github.com/jedib0t/go-pretty/v6/table/table.go b/vendor/github.com/jedib0t/go-pretty/v6/table/table.go index 34e5a348d1..35426c5ca7 100644 --- a/vendor/github.com/jedib0t/go-pretty/v6/table/table.go +++ b/vendor/github.com/jedib0t/go-pretty/v6/table/table.go @@ -356,6 +356,12 @@ func (t *Table) getAlign(colIdx int, hint renderHint) text.Align { align = text.AlignRight } else if hint.isAutoIndexRow { align = text.AlignCenter + } else if hint.isHeaderRow { + align = t.style.Format.HeaderAlign + } else if hint.isFooterRow { + align = t.style.Format.FooterAlign + } else { + align = t.style.Format.RowAlign } } return align @@ -671,6 +677,15 @@ func (t *Table) getVAlign(colIdx int, hint renderHint) text.VAlign { vAlign = cfg.VAlign } } + if vAlign == text.VAlignDefault { + if hint.isHeaderRow { + vAlign = t.style.Format.HeaderVAlign + } else if hint.isFooterRow { + vAlign = t.style.Format.FooterVAlign + } else { + vAlign = t.style.Format.RowVAlign + } + } return vAlign } diff --git a/vendor/modules.txt b/vendor/modules.txt index 2d84a00b53..6f45a44132 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -313,7 +313,7 @@ github.com/inconshreveable/mousetrap # github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 ## explicit github.com/jbenet/go-context/io -# github.com/jedib0t/go-pretty/v6 v6.6.1 +# github.com/jedib0t/go-pretty/v6 v6.6.2 ## explicit; go 1.17 github.com/jedib0t/go-pretty/v6/table github.com/jedib0t/go-pretty/v6/text @@ -1121,7 +1121,6 @@ knative.dev/pkg/tracker knative.dev/pkg/webhook/resourcesemantics # sigs.k8s.io/controller-runtime v0.18.5 ## explicit; go 1.22.0 -sigs.k8s.io/controller-runtime/pkg/builder sigs.k8s.io/controller-runtime/pkg/cache sigs.k8s.io/controller-runtime/pkg/cache/internal sigs.k8s.io/controller-runtime/pkg/certwatcher @@ -1133,7 +1132,6 @@ sigs.k8s.io/controller-runtime/pkg/cluster sigs.k8s.io/controller-runtime/pkg/config sigs.k8s.io/controller-runtime/pkg/controller sigs.k8s.io/controller-runtime/pkg/controller/controllerutil -sigs.k8s.io/controller-runtime/pkg/conversion sigs.k8s.io/controller-runtime/pkg/event sigs.k8s.io/controller-runtime/pkg/handler sigs.k8s.io/controller-runtime/pkg/healthz @@ -1160,7 +1158,6 @@ sigs.k8s.io/controller-runtime/pkg/scheme sigs.k8s.io/controller-runtime/pkg/source sigs.k8s.io/controller-runtime/pkg/webhook sigs.k8s.io/controller-runtime/pkg/webhook/admission -sigs.k8s.io/controller-runtime/pkg/webhook/conversion sigs.k8s.io/controller-runtime/pkg/webhook/internal/metrics # sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd ## explicit; go 1.18 diff --git a/vendor/sigs.k8s.io/controller-runtime/pkg/builder/controller.go b/vendor/sigs.k8s.io/controller-runtime/pkg/builder/controller.go deleted file mode 100644 index 2c0063a837..0000000000 --- a/vendor/sigs.k8s.io/controller-runtime/pkg/builder/controller.go +++ /dev/null @@ -1,421 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package builder - -import ( - "errors" - "fmt" - "strings" - - "github.com/go-logr/logr" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/klog/v2" - - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/client/apiutil" - "sigs.k8s.io/controller-runtime/pkg/controller" - "sigs.k8s.io/controller-runtime/pkg/handler" - "sigs.k8s.io/controller-runtime/pkg/manager" - "sigs.k8s.io/controller-runtime/pkg/predicate" - "sigs.k8s.io/controller-runtime/pkg/reconcile" - "sigs.k8s.io/controller-runtime/pkg/source" -) - -// Supporting mocking out functions for testing. -var newController = controller.New -var getGvk = apiutil.GVKForObject - -// project represents other forms that we can use to -// send/receive a given resource (metadata-only, unstructured, etc). -type objectProjection int - -const ( - // projectAsNormal doesn't change the object from the form given. - projectAsNormal objectProjection = iota - // projectAsMetadata turns this into a metadata-only watch. - projectAsMetadata -) - -// Builder builds a Controller. -type Builder struct { - forInput ForInput - ownsInput []OwnsInput - rawSources []source.Source - watchesInput []WatchesInput - mgr manager.Manager - globalPredicates []predicate.Predicate - ctrl controller.Controller - ctrlOptions controller.Options - name string -} - -// ControllerManagedBy returns a new controller builder that will be started by the provided Manager. -func ControllerManagedBy(m manager.Manager) *Builder { - return &Builder{mgr: m} -} - -// ForInput represents the information set by the For method. -type ForInput struct { - object client.Object - predicates []predicate.Predicate - objectProjection objectProjection - err error -} - -// For defines the type of Object being *reconciled*, and configures the ControllerManagedBy to respond to create / delete / -// update events by *reconciling the object*. -// This is the equivalent of calling -// Watches(&source.Kind{Type: apiType}, &handler.EnqueueRequestForObject{}). -func (blder *Builder) For(object client.Object, opts ...ForOption) *Builder { - if blder.forInput.object != nil { - blder.forInput.err = fmt.Errorf("For(...) should only be called once, could not assign multiple objects for reconciliation") - return blder - } - input := ForInput{object: object} - for _, opt := range opts { - opt.ApplyToFor(&input) - } - - blder.forInput = input - return blder -} - -// OwnsInput represents the information set by Owns method. -type OwnsInput struct { - matchEveryOwner bool - object client.Object - predicates []predicate.Predicate - objectProjection objectProjection -} - -// Owns defines types of Objects being *generated* by the ControllerManagedBy, and configures the ControllerManagedBy to respond to -// create / delete / update events by *reconciling the owner object*. -// -// The default behavior reconciles only the first controller-type OwnerReference of the given type. -// Use Owns(object, builder.MatchEveryOwner) to reconcile all owners. -// -// By default, this is the equivalent of calling -// Watches(object, handler.EnqueueRequestForOwner([...], ownerType, OnlyControllerOwner())). -func (blder *Builder) Owns(object client.Object, opts ...OwnsOption) *Builder { - input := OwnsInput{object: object} - for _, opt := range opts { - opt.ApplyToOwns(&input) - } - - blder.ownsInput = append(blder.ownsInput, input) - return blder -} - -// WatchesInput represents the information set by Watches method. -type WatchesInput struct { - obj client.Object - handler handler.EventHandler - predicates []predicate.Predicate - objectProjection objectProjection -} - -// Watches defines the type of Object to watch, and configures the ControllerManagedBy to respond to create / delete / -// update events by *reconciling the object* with the given EventHandler. -// -// This is the equivalent of calling -// WatchesRawSource(source.Kind(cache, object, eventHandler, predicates...)). -func (blder *Builder) Watches(object client.Object, eventHandler handler.EventHandler, opts ...WatchesOption) *Builder { - input := WatchesInput{ - obj: object, - handler: eventHandler, - } - for _, opt := range opts { - opt.ApplyToWatches(&input) - } - - blder.watchesInput = append(blder.watchesInput, input) - - return blder -} - -// WatchesMetadata is the same as Watches, but forces the internal cache to only watch PartialObjectMetadata. -// -// This is useful when watching lots of objects, really big objects, or objects for which you only know -// the GVK, but not the structure. You'll need to pass metav1.PartialObjectMetadata to the client -// when fetching objects in your reconciler, otherwise you'll end up with a duplicate structured or unstructured cache. -// -// When watching a resource with metadata only, for example the v1.Pod, you should not Get and List using the v1.Pod type. -// Instead, you should use the special metav1.PartialObjectMetadata type. -// -// ❌ Incorrect: -// -// pod := &v1.Pod{} -// mgr.GetClient().Get(ctx, nsAndName, pod) -// -// ✅ Correct: -// -// pod := &metav1.PartialObjectMetadata{} -// pod.SetGroupVersionKind(schema.GroupVersionKind{ -// Group: "", -// Version: "v1", -// Kind: "Pod", -// }) -// mgr.GetClient().Get(ctx, nsAndName, pod) -// -// In the first case, controller-runtime will create another cache for the -// concrete type on top of the metadata cache; this increases memory -// consumption and leads to race conditions as caches are not in sync. -func (blder *Builder) WatchesMetadata(object client.Object, eventHandler handler.EventHandler, opts ...WatchesOption) *Builder { - opts = append(opts, OnlyMetadata) - return blder.Watches(object, eventHandler, opts...) -} - -// WatchesRawSource exposes the lower-level ControllerManagedBy Watches functions through the builder. -// Specified predicates are registered only for given source. -// -// STOP! Consider using For(...), Owns(...), Watches(...), WatchesMetadata(...) instead. -// This method is only exposed for more advanced use cases, most users should use one of the higher level functions. -// -// WatchesRawSource does not respect predicates configured through WithEventFilter. -func (blder *Builder) WatchesRawSource(src source.Source) *Builder { - blder.rawSources = append(blder.rawSources, src) - - return blder -} - -// WithEventFilter sets the event filters, to filter which create/update/delete/generic events eventually -// trigger reconciliations. For example, filtering on whether the resource version has changed. -// Given predicate is added for all watched objects. -// Defaults to the empty list. -func (blder *Builder) WithEventFilter(p predicate.Predicate) *Builder { - blder.globalPredicates = append(blder.globalPredicates, p) - return blder -} - -// WithOptions overrides the controller options used in doController. Defaults to empty. -func (blder *Builder) WithOptions(options controller.Options) *Builder { - blder.ctrlOptions = options - return blder -} - -// WithLogConstructor overrides the controller options's LogConstructor. -func (blder *Builder) WithLogConstructor(logConstructor func(*reconcile.Request) logr.Logger) *Builder { - blder.ctrlOptions.LogConstructor = logConstructor - return blder -} - -// Named sets the name of the controller to the given name. The name shows up -// in metrics, among other things, and thus should be a prometheus compatible name -// (underscores and alphanumeric characters only). -// -// By default, controllers are named using the lowercase version of their kind. -func (blder *Builder) Named(name string) *Builder { - blder.name = name - return blder -} - -// Complete builds the Application Controller. -func (blder *Builder) Complete(r reconcile.Reconciler) error { - _, err := blder.Build(r) - return err -} - -// Build builds the Application Controller and returns the Controller it created. -func (blder *Builder) Build(r reconcile.Reconciler) (controller.Controller, error) { - if r == nil { - return nil, fmt.Errorf("must provide a non-nil Reconciler") - } - if blder.mgr == nil { - return nil, fmt.Errorf("must provide a non-nil Manager") - } - if blder.forInput.err != nil { - return nil, blder.forInput.err - } - - // Set the ControllerManagedBy - if err := blder.doController(r); err != nil { - return nil, err - } - - // Set the Watch - if err := blder.doWatch(); err != nil { - return nil, err - } - - return blder.ctrl, nil -} - -func (blder *Builder) project(obj client.Object, proj objectProjection) (client.Object, error) { - switch proj { - case projectAsNormal: - return obj, nil - case projectAsMetadata: - metaObj := &metav1.PartialObjectMetadata{} - gvk, err := getGvk(obj, blder.mgr.GetScheme()) - if err != nil { - return nil, fmt.Errorf("unable to determine GVK of %T for a metadata-only watch: %w", obj, err) - } - metaObj.SetGroupVersionKind(gvk) - return metaObj, nil - default: - panic(fmt.Sprintf("unexpected projection type %v on type %T, should not be possible since this is an internal field", proj, obj)) - } -} - -func (blder *Builder) doWatch() error { - // Reconcile type - if blder.forInput.object != nil { - obj, err := blder.project(blder.forInput.object, blder.forInput.objectProjection) - if err != nil { - return err - } - hdler := &handler.EnqueueRequestForObject{} - allPredicates := append([]predicate.Predicate(nil), blder.globalPredicates...) - allPredicates = append(allPredicates, blder.forInput.predicates...) - src := source.Kind(blder.mgr.GetCache(), obj, hdler, allPredicates...) - if err := blder.ctrl.Watch(src); err != nil { - return err - } - } - - // Watches the managed types - if len(blder.ownsInput) > 0 && blder.forInput.object == nil { - return errors.New("Owns() can only be used together with For()") - } - for _, own := range blder.ownsInput { - obj, err := blder.project(own.object, own.objectProjection) - if err != nil { - return err - } - opts := []handler.OwnerOption{} - if !own.matchEveryOwner { - opts = append(opts, handler.OnlyControllerOwner()) - } - hdler := handler.EnqueueRequestForOwner( - blder.mgr.GetScheme(), blder.mgr.GetRESTMapper(), - blder.forInput.object, - opts..., - ) - allPredicates := append([]predicate.Predicate(nil), blder.globalPredicates...) - allPredicates = append(allPredicates, own.predicates...) - src := source.Kind(blder.mgr.GetCache(), obj, hdler, allPredicates...) - if err := blder.ctrl.Watch(src); err != nil { - return err - } - } - - // Do the watch requests - if len(blder.watchesInput) == 0 && blder.forInput.object == nil && len(blder.rawSources) == 0 { - return errors.New("there are no watches configured, controller will never get triggered. Use For(), Owns(), Watches() or WatchesRawSource() to set them up") - } - for _, w := range blder.watchesInput { - projected, err := blder.project(w.obj, w.objectProjection) - if err != nil { - return fmt.Errorf("failed to project for %T: %w", w.obj, err) - } - allPredicates := append([]predicate.Predicate(nil), blder.globalPredicates...) - allPredicates = append(allPredicates, w.predicates...) - if err := blder.ctrl.Watch(source.Kind(blder.mgr.GetCache(), projected, w.handler, allPredicates...)); err != nil { - return err - } - } - for _, src := range blder.rawSources { - if err := blder.ctrl.Watch(src); err != nil { - return err - } - } - return nil -} - -func (blder *Builder) getControllerName(gvk schema.GroupVersionKind, hasGVK bool) (string, error) { - if blder.name != "" { - return blder.name, nil - } - if !hasGVK { - return "", errors.New("one of For() or Named() must be called") - } - return strings.ToLower(gvk.Kind), nil -} - -func (blder *Builder) doController(r reconcile.Reconciler) error { - globalOpts := blder.mgr.GetControllerOptions() - - ctrlOptions := blder.ctrlOptions - if ctrlOptions.Reconciler != nil && r != nil { - return errors.New("reconciler was set via WithOptions() and via Build() or Complete()") - } - if ctrlOptions.Reconciler == nil { - ctrlOptions.Reconciler = r - } - - // Retrieve the GVK from the object we're reconciling - // to pre-populate logger information, and to optionally generate a default name. - var gvk schema.GroupVersionKind - hasGVK := blder.forInput.object != nil - if hasGVK { - var err error - gvk, err = getGvk(blder.forInput.object, blder.mgr.GetScheme()) - if err != nil { - return err - } - } - - // Setup concurrency. - if ctrlOptions.MaxConcurrentReconciles == 0 && hasGVK { - groupKind := gvk.GroupKind().String() - - if concurrency, ok := globalOpts.GroupKindConcurrency[groupKind]; ok && concurrency > 0 { - ctrlOptions.MaxConcurrentReconciles = concurrency - } - } - - // Setup cache sync timeout. - if ctrlOptions.CacheSyncTimeout == 0 && globalOpts.CacheSyncTimeout > 0 { - ctrlOptions.CacheSyncTimeout = globalOpts.CacheSyncTimeout - } - - controllerName, err := blder.getControllerName(gvk, hasGVK) - if err != nil { - return err - } - - // Setup the logger. - if ctrlOptions.LogConstructor == nil { - log := blder.mgr.GetLogger().WithValues( - "controller", controllerName, - ) - if hasGVK { - log = log.WithValues( - "controllerGroup", gvk.Group, - "controllerKind", gvk.Kind, - ) - } - - ctrlOptions.LogConstructor = func(req *reconcile.Request) logr.Logger { - log := log - if req != nil { - if hasGVK { - log = log.WithValues(gvk.Kind, klog.KRef(req.Namespace, req.Name)) - } - log = log.WithValues( - "namespace", req.Namespace, "name", req.Name, - ) - } - return log - } - } - - // Build the controller and return. - blder.ctrl, err = newController(controllerName, blder.mgr, ctrlOptions) - return err -} diff --git a/vendor/sigs.k8s.io/controller-runtime/pkg/builder/doc.go b/vendor/sigs.k8s.io/controller-runtime/pkg/builder/doc.go deleted file mode 100644 index e4df1b709f..0000000000 --- a/vendor/sigs.k8s.io/controller-runtime/pkg/builder/doc.go +++ /dev/null @@ -1,28 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Package builder wraps other controller-runtime libraries and exposes simple -// patterns for building common Controllers. -// -// Projects built with the builder package can trivially be rebased on top of the underlying -// packages if the project requires more customized behavior in the future. -package builder - -import ( - logf "sigs.k8s.io/controller-runtime/pkg/internal/log" -) - -var log = logf.RuntimeLog.WithName("builder") diff --git a/vendor/sigs.k8s.io/controller-runtime/pkg/builder/options.go b/vendor/sigs.k8s.io/controller-runtime/pkg/builder/options.go deleted file mode 100644 index 15f66b2a82..0000000000 --- a/vendor/sigs.k8s.io/controller-runtime/pkg/builder/options.go +++ /dev/null @@ -1,156 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package builder - -import ( - "sigs.k8s.io/controller-runtime/pkg/predicate" -) - -// {{{ "Functional" Option Interfaces - -// ForOption is some configuration that modifies options for a For request. -type ForOption interface { - // ApplyToFor applies this configuration to the given for input. - ApplyToFor(*ForInput) -} - -// OwnsOption is some configuration that modifies options for an owns request. -type OwnsOption interface { - // ApplyToOwns applies this configuration to the given owns input. - ApplyToOwns(*OwnsInput) -} - -// WatchesOption is some configuration that modifies options for a watches request. -type WatchesOption interface { - // ApplyToWatches applies this configuration to the given watches options. - ApplyToWatches(*WatchesInput) -} - -// }}} - -// {{{ Multi-Type Options - -// WithPredicates sets the given predicates list. -func WithPredicates(predicates ...predicate.Predicate) Predicates { - return Predicates{ - predicates: predicates, - } -} - -// Predicates filters events before enqueuing the keys. -type Predicates struct { - predicates []predicate.Predicate -} - -// ApplyToFor applies this configuration to the given ForInput options. -func (w Predicates) ApplyToFor(opts *ForInput) { - opts.predicates = w.predicates -} - -// ApplyToOwns applies this configuration to the given OwnsInput options. -func (w Predicates) ApplyToOwns(opts *OwnsInput) { - opts.predicates = w.predicates -} - -// ApplyToWatches applies this configuration to the given WatchesInput options. -func (w Predicates) ApplyToWatches(opts *WatchesInput) { - opts.predicates = w.predicates -} - -var _ ForOption = &Predicates{} -var _ OwnsOption = &Predicates{} -var _ WatchesOption = &Predicates{} - -// }}} - -// {{{ For & Owns Dual-Type options - -// projectAs configures the projection on the input. -// Currently only OnlyMetadata is supported. We might want to expand -// this to arbitrary non-special local projections in the future. -type projectAs objectProjection - -// ApplyToFor applies this configuration to the given ForInput options. -func (p projectAs) ApplyToFor(opts *ForInput) { - opts.objectProjection = objectProjection(p) -} - -// ApplyToOwns applies this configuration to the given OwnsInput options. -func (p projectAs) ApplyToOwns(opts *OwnsInput) { - opts.objectProjection = objectProjection(p) -} - -// ApplyToWatches applies this configuration to the given WatchesInput options. -func (p projectAs) ApplyToWatches(opts *WatchesInput) { - opts.objectProjection = objectProjection(p) -} - -var ( - // OnlyMetadata tells the controller to *only* cache metadata, and to watch - // the API server in metadata-only form. This is useful when watching - // lots of objects, really big objects, or objects for which you only know - // the GVK, but not the structure. You'll need to pass - // metav1.PartialObjectMetadata to the client when fetching objects in your - // reconciler, otherwise you'll end up with a duplicate structured or - // unstructured cache. - // - // When watching a resource with OnlyMetadata, for example the v1.Pod, you - // should not Get and List using the v1.Pod type. Instead, you should use - // the special metav1.PartialObjectMetadata type. - // - // ❌ Incorrect: - // - // pod := &v1.Pod{} - // mgr.GetClient().Get(ctx, nsAndName, pod) - // - // ✅ Correct: - // - // pod := &metav1.PartialObjectMetadata{} - // pod.SetGroupVersionKind(schema.GroupVersionKind{ - // Group: "", - // Version: "v1", - // Kind: "Pod", - // }) - // mgr.GetClient().Get(ctx, nsAndName, pod) - // - // In the first case, controller-runtime will create another cache for the - // concrete type on top of the metadata cache; this increases memory - // consumption and leads to race conditions as caches are not in sync. - OnlyMetadata = projectAs(projectAsMetadata) - - _ ForOption = OnlyMetadata - _ OwnsOption = OnlyMetadata - _ WatchesOption = OnlyMetadata -) - -// }}} - -// MatchEveryOwner determines whether the watch should be filtered based on -// controller ownership. As in, when the OwnerReference.Controller field is set. -// -// If passed as an option, -// the handler receives notification for every owner of the object with the given type. -// If unset (default), the handler receives notification only for the first -// OwnerReference with `Controller: true`. -var MatchEveryOwner = &matchEveryOwner{} - -type matchEveryOwner struct{} - -// ApplyToOwns applies this configuration to the given OwnsInput options. -func (o matchEveryOwner) ApplyToOwns(opts *OwnsInput) { - opts.matchEveryOwner = true -} diff --git a/vendor/sigs.k8s.io/controller-runtime/pkg/builder/webhook.go b/vendor/sigs.k8s.io/controller-runtime/pkg/builder/webhook.go deleted file mode 100644 index 6170180c74..0000000000 --- a/vendor/sigs.k8s.io/controller-runtime/pkg/builder/webhook.go +++ /dev/null @@ -1,256 +0,0 @@ -/* -Copyright 2019 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package builder - -import ( - "errors" - "net/http" - "net/url" - "strings" - - "github.com/go-logr/logr" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/client-go/rest" - "k8s.io/klog/v2" - - "sigs.k8s.io/controller-runtime/pkg/client/apiutil" - "sigs.k8s.io/controller-runtime/pkg/manager" - "sigs.k8s.io/controller-runtime/pkg/webhook/admission" - "sigs.k8s.io/controller-runtime/pkg/webhook/conversion" -) - -// WebhookBuilder builds a Webhook. -type WebhookBuilder struct { - apiType runtime.Object - customDefaulter admission.CustomDefaulter - customValidator admission.CustomValidator - gvk schema.GroupVersionKind - mgr manager.Manager - config *rest.Config - recoverPanic bool - logConstructor func(base logr.Logger, req *admission.Request) logr.Logger - err error -} - -// WebhookManagedBy returns a new webhook builder. -func WebhookManagedBy(m manager.Manager) *WebhookBuilder { - return &WebhookBuilder{mgr: m} -} - -// TODO(droot): update the GoDoc for conversion. - -// For takes a runtime.Object which should be a CR. -// If the given object implements the admission.Defaulter interface, a MutatingWebhook will be wired for this type. -// If the given object implements the admission.Validator interface, a ValidatingWebhook will be wired for this type. -func (blder *WebhookBuilder) For(apiType runtime.Object) *WebhookBuilder { - if blder.apiType != nil { - blder.err = errors.New("For(...) should only be called once, could not assign multiple objects for webhook registration") - } - blder.apiType = apiType - return blder -} - -// WithDefaulter takes an admission.CustomDefaulter interface, a MutatingWebhook will be wired for this type. -func (blder *WebhookBuilder) WithDefaulter(defaulter admission.CustomDefaulter) *WebhookBuilder { - blder.customDefaulter = defaulter - return blder -} - -// WithValidator takes a admission.CustomValidator interface, a ValidatingWebhook will be wired for this type. -func (blder *WebhookBuilder) WithValidator(validator admission.CustomValidator) *WebhookBuilder { - blder.customValidator = validator - return blder -} - -// WithLogConstructor overrides the webhook's LogConstructor. -func (blder *WebhookBuilder) WithLogConstructor(logConstructor func(base logr.Logger, req *admission.Request) logr.Logger) *WebhookBuilder { - blder.logConstructor = logConstructor - return blder -} - -// RecoverPanic indicates whether panics caused by the webhook should be recovered. -func (blder *WebhookBuilder) RecoverPanic() *WebhookBuilder { - blder.recoverPanic = true - return blder -} - -// Complete builds the webhook. -func (blder *WebhookBuilder) Complete() error { - // Set the Config - blder.loadRestConfig() - - // Configure the default LogConstructor - blder.setLogConstructor() - - // Set the Webhook if needed - return blder.registerWebhooks() -} - -func (blder *WebhookBuilder) loadRestConfig() { - if blder.config == nil { - blder.config = blder.mgr.GetConfig() - } -} - -func (blder *WebhookBuilder) setLogConstructor() { - if blder.logConstructor == nil { - blder.logConstructor = func(base logr.Logger, req *admission.Request) logr.Logger { - log := base.WithValues( - "webhookGroup", blder.gvk.Group, - "webhookKind", blder.gvk.Kind, - ) - if req != nil { - return log.WithValues( - blder.gvk.Kind, klog.KRef(req.Namespace, req.Name), - "namespace", req.Namespace, "name", req.Name, - "resource", req.Resource, "user", req.UserInfo.Username, - "requestID", req.UID, - ) - } - return log - } - } -} - -func (blder *WebhookBuilder) registerWebhooks() error { - typ, err := blder.getType() - if err != nil { - return err - } - - blder.gvk, err = apiutil.GVKForObject(typ, blder.mgr.GetScheme()) - if err != nil { - return err - } - - // Register webhook(s) for type - blder.registerDefaultingWebhook() - blder.registerValidatingWebhook() - - err = blder.registerConversionWebhook() - if err != nil { - return err - } - return blder.err -} - -// registerDefaultingWebhook registers a defaulting webhook if necessary. -func (blder *WebhookBuilder) registerDefaultingWebhook() { - mwh := blder.getDefaultingWebhook() - if mwh != nil { - mwh.LogConstructor = blder.logConstructor - path := generateMutatePath(blder.gvk) - - // Checking if the path is already registered. - // If so, just skip it. - if !blder.isAlreadyHandled(path) { - log.Info("Registering a mutating webhook", - "GVK", blder.gvk, - "path", path) - blder.mgr.GetWebhookServer().Register(path, mwh) - } - } -} - -func (blder *WebhookBuilder) getDefaultingWebhook() *admission.Webhook { - if defaulter := blder.customDefaulter; defaulter != nil { - return admission.WithCustomDefaulter(blder.mgr.GetScheme(), blder.apiType, defaulter).WithRecoverPanic(blder.recoverPanic) - } - if defaulter, ok := blder.apiType.(admission.Defaulter); ok { - return admission.DefaultingWebhookFor(blder.mgr.GetScheme(), defaulter).WithRecoverPanic(blder.recoverPanic) - } - log.Info( - "skip registering a mutating webhook, object does not implement admission.Defaulter or WithDefaulter wasn't called", - "GVK", blder.gvk) - return nil -} - -// registerValidatingWebhook registers a validating webhook if necessary. -func (blder *WebhookBuilder) registerValidatingWebhook() { - vwh := blder.getValidatingWebhook() - if vwh != nil { - vwh.LogConstructor = blder.logConstructor - path := generateValidatePath(blder.gvk) - - // Checking if the path is already registered. - // If so, just skip it. - if !blder.isAlreadyHandled(path) { - log.Info("Registering a validating webhook", - "GVK", blder.gvk, - "path", path) - blder.mgr.GetWebhookServer().Register(path, vwh) - } - } -} - -func (blder *WebhookBuilder) getValidatingWebhook() *admission.Webhook { - if validator := blder.customValidator; validator != nil { - return admission.WithCustomValidator(blder.mgr.GetScheme(), blder.apiType, validator).WithRecoverPanic(blder.recoverPanic) - } - if validator, ok := blder.apiType.(admission.Validator); ok { - return admission.ValidatingWebhookFor(blder.mgr.GetScheme(), validator).WithRecoverPanic(blder.recoverPanic) - } - log.Info( - "skip registering a validating webhook, object does not implement admission.Validator or WithValidator wasn't called", - "GVK", blder.gvk) - return nil -} - -func (blder *WebhookBuilder) registerConversionWebhook() error { - ok, err := conversion.IsConvertible(blder.mgr.GetScheme(), blder.apiType) - if err != nil { - log.Error(err, "conversion check failed", "GVK", blder.gvk) - return err - } - if ok { - if !blder.isAlreadyHandled("/convert") { - blder.mgr.GetWebhookServer().Register("/convert", conversion.NewWebhookHandler(blder.mgr.GetScheme())) - } - log.Info("Conversion webhook enabled", "GVK", blder.gvk) - } - - return nil -} - -func (blder *WebhookBuilder) getType() (runtime.Object, error) { - if blder.apiType != nil { - return blder.apiType, nil - } - return nil, errors.New("For() must be called with a valid object") -} - -func (blder *WebhookBuilder) isAlreadyHandled(path string) bool { - if blder.mgr.GetWebhookServer().WebhookMux() == nil { - return false - } - h, p := blder.mgr.GetWebhookServer().WebhookMux().Handler(&http.Request{URL: &url.URL{Path: path}}) - if p == path && h != nil { - return true - } - return false -} - -func generateMutatePath(gvk schema.GroupVersionKind) string { - return "/mutate-" + strings.ReplaceAll(gvk.Group, ".", "-") + "-" + - gvk.Version + "-" + strings.ToLower(gvk.Kind) -} - -func generateValidatePath(gvk schema.GroupVersionKind) string { - return "/validate-" + strings.ReplaceAll(gvk.Group, ".", "-") + "-" + - gvk.Version + "-" + strings.ToLower(gvk.Kind) -} diff --git a/vendor/sigs.k8s.io/controller-runtime/pkg/conversion/conversion.go b/vendor/sigs.k8s.io/controller-runtime/pkg/conversion/conversion.go deleted file mode 100644 index da32ab48e4..0000000000 --- a/vendor/sigs.k8s.io/controller-runtime/pkg/conversion/conversion.go +++ /dev/null @@ -1,40 +0,0 @@ -/* -Copyright 2019 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -/* -Package conversion provides interface definitions that an API Type needs to -implement for it to be supported by the generic conversion webhook handler -defined under pkg/webhook/conversion. -*/ -package conversion - -import "k8s.io/apimachinery/pkg/runtime" - -// Convertible defines capability of a type to convertible i.e. it can be converted to/from a hub type. -type Convertible interface { - runtime.Object - ConvertTo(dst Hub) error - ConvertFrom(src Hub) error -} - -// Hub marks that a given type is the hub type for conversion. This means that -// all conversions will first convert to the hub type, then convert from the hub -// type to the destination type. All types besides the hub type should implement -// Convertible. -type Hub interface { - runtime.Object - Hub() -} diff --git a/vendor/sigs.k8s.io/controller-runtime/pkg/webhook/conversion/conversion.go b/vendor/sigs.k8s.io/controller-runtime/pkg/webhook/conversion/conversion.go deleted file mode 100644 index 249a364b38..0000000000 --- a/vendor/sigs.k8s.io/controller-runtime/pkg/webhook/conversion/conversion.go +++ /dev/null @@ -1,343 +0,0 @@ -/* -Copyright 2019 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -/* -Package conversion provides implementation for CRD conversion webhook that implements handler for version conversion requests for types that are convertible. - -See pkg/conversion for interface definitions required to ensure an API Type is convertible. -*/ -package conversion - -import ( - "encoding/json" - "fmt" - "net/http" - - apix "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" - "k8s.io/apimachinery/pkg/api/meta" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "sigs.k8s.io/controller-runtime/pkg/conversion" - logf "sigs.k8s.io/controller-runtime/pkg/log" -) - -var ( - log = logf.Log.WithName("conversion-webhook") -) - -func NewWebhookHandler(scheme *runtime.Scheme) http.Handler { - return &webhook{scheme: scheme, decoder: NewDecoder(scheme)} -} - -// webhook implements a CRD conversion webhook HTTP handler. -type webhook struct { - scheme *runtime.Scheme - decoder *Decoder -} - -// ensure Webhook implements http.Handler -var _ http.Handler = &webhook{} - -func (wh *webhook) ServeHTTP(w http.ResponseWriter, r *http.Request) { - convertReview := &apix.ConversionReview{} - err := json.NewDecoder(r.Body).Decode(convertReview) - if err != nil { - log.Error(err, "failed to read conversion request") - w.WriteHeader(http.StatusBadRequest) - return - } - - if convertReview.Request == nil { - log.Error(nil, "conversion request is nil") - w.WriteHeader(http.StatusBadRequest) - return - } - - // TODO(droot): may be move the conversion logic to a separate module to - // decouple it from the http layer ? - resp, err := wh.handleConvertRequest(convertReview.Request) - if err != nil { - log.Error(err, "failed to convert", "request", convertReview.Request.UID) - convertReview.Response = errored(err) - } else { - convertReview.Response = resp - } - convertReview.Response.UID = convertReview.Request.UID - convertReview.Request = nil - - err = json.NewEncoder(w).Encode(convertReview) - if err != nil { - log.Error(err, "failed to write response") - return - } -} - -// handles a version conversion request. -func (wh *webhook) handleConvertRequest(req *apix.ConversionRequest) (*apix.ConversionResponse, error) { - if req == nil { - return nil, fmt.Errorf("conversion request is nil") - } - var objects []runtime.RawExtension - - for _, obj := range req.Objects { - src, gvk, err := wh.decoder.Decode(obj.Raw) - if err != nil { - return nil, err - } - dst, err := wh.allocateDstObject(req.DesiredAPIVersion, gvk.Kind) - if err != nil { - return nil, err - } - err = wh.convertObject(src, dst) - if err != nil { - return nil, err - } - objects = append(objects, runtime.RawExtension{Object: dst}) - } - return &apix.ConversionResponse{ - UID: req.UID, - ConvertedObjects: objects, - Result: metav1.Status{ - Status: metav1.StatusSuccess, - }, - }, nil -} - -// convertObject will convert given a src object to dst object. -// Note(droot): couldn't find a way to reduce the cyclomatic complexity under 10 -// without compromising readability, so disabling gocyclo linter -func (wh *webhook) convertObject(src, dst runtime.Object) error { - srcGVK := src.GetObjectKind().GroupVersionKind() - dstGVK := dst.GetObjectKind().GroupVersionKind() - - if srcGVK.GroupKind() != dstGVK.GroupKind() { - return fmt.Errorf("src %T and dst %T does not belong to same API Group", src, dst) - } - - if srcGVK == dstGVK { - return fmt.Errorf("conversion is not allowed between same type %T", src) - } - - srcIsHub, dstIsHub := isHub(src), isHub(dst) - srcIsConvertible, dstIsConvertible := isConvertible(src), isConvertible(dst) - - switch { - case srcIsHub && dstIsConvertible: - return dst.(conversion.Convertible).ConvertFrom(src.(conversion.Hub)) - case dstIsHub && srcIsConvertible: - return src.(conversion.Convertible).ConvertTo(dst.(conversion.Hub)) - case srcIsConvertible && dstIsConvertible: - return wh.convertViaHub(src.(conversion.Convertible), dst.(conversion.Convertible)) - default: - return fmt.Errorf("%T is not convertible to %T", src, dst) - } -} - -func (wh *webhook) convertViaHub(src, dst conversion.Convertible) error { - hub, err := wh.getHub(src) - if err != nil { - return err - } - - if hub == nil { - return fmt.Errorf("%s does not have any Hub defined", src) - } - - err = src.ConvertTo(hub) - if err != nil { - return fmt.Errorf("%T failed to convert to hub version %T : %w", src, hub, err) - } - - err = dst.ConvertFrom(hub) - if err != nil { - return fmt.Errorf("%T failed to convert from hub version %T : %w", dst, hub, err) - } - - return nil -} - -// getHub returns an instance of the Hub for passed-in object's group/kind. -func (wh *webhook) getHub(obj runtime.Object) (conversion.Hub, error) { - gvks, err := objectGVKs(wh.scheme, obj) - if err != nil { - return nil, err - } - if len(gvks) == 0 { - return nil, fmt.Errorf("error retrieving gvks for object : %v", obj) - } - - var hub conversion.Hub - var hubFoundAlready bool - for _, gvk := range gvks { - instance, err := wh.scheme.New(gvk) - if err != nil { - return nil, fmt.Errorf("failed to allocate an instance for gvk %v: %w", gvk, err) - } - if val, isHub := instance.(conversion.Hub); isHub { - if hubFoundAlready { - return nil, fmt.Errorf("multiple hub version defined for %T", obj) - } - hubFoundAlready = true - hub = val - } - } - return hub, nil -} - -// allocateDstObject returns an instance for a given GVK. -func (wh *webhook) allocateDstObject(apiVersion, kind string) (runtime.Object, error) { - gvk := schema.FromAPIVersionAndKind(apiVersion, kind) - - obj, err := wh.scheme.New(gvk) - if err != nil { - return obj, err - } - - t, err := meta.TypeAccessor(obj) - if err != nil { - return obj, err - } - - t.SetAPIVersion(apiVersion) - t.SetKind(kind) - - return obj, nil -} - -// IsConvertible determines if given type is convertible or not. For a type -// to be convertible, the group-kind needs to have a Hub type defined and all -// non-hub types must be able to convert to/from Hub. -func IsConvertible(scheme *runtime.Scheme, obj runtime.Object) (bool, error) { - var hubs, spokes, nonSpokes []runtime.Object - - gvks, err := objectGVKs(scheme, obj) - if err != nil { - return false, err - } - if len(gvks) == 0 { - return false, fmt.Errorf("error retrieving gvks for object : %v", obj) - } - - for _, gvk := range gvks { - instance, err := scheme.New(gvk) - if err != nil { - return false, fmt.Errorf("failed to allocate an instance for gvk %v: %w", gvk, err) - } - - if isHub(instance) { - hubs = append(hubs, instance) - continue - } - - if !isConvertible(instance) { - nonSpokes = append(nonSpokes, instance) - continue - } - - spokes = append(spokes, instance) - } - - if len(gvks) == 1 { - return false, nil // single version - } - - if len(hubs) == 0 && len(spokes) == 0 { - // multiple version detected with no conversion implementation. This is - // true for multi-version built-in types. - return false, nil - } - - if len(hubs) == 1 && len(nonSpokes) == 0 { // convertible - return true, nil - } - - return false, PartialImplementationError{ - hubs: hubs, - nonSpokes: nonSpokes, - spokes: spokes, - } -} - -// objectGVKs returns all (Group,Version,Kind) for the Group/Kind of given object. -func objectGVKs(scheme *runtime.Scheme, obj runtime.Object) ([]schema.GroupVersionKind, error) { - // NB: we should not use `obj.GetObjectKind().GroupVersionKind()` to get the - // GVK here, since it is parsed from apiVersion and kind fields and it may - // return empty GVK if obj is an uninitialized object. - objGVKs, _, err := scheme.ObjectKinds(obj) - if err != nil { - return nil, err - } - if len(objGVKs) != 1 { - return nil, fmt.Errorf("expect to get only one GVK for %v", obj) - } - objGVK := objGVKs[0] - knownTypes := scheme.AllKnownTypes() - - var gvks []schema.GroupVersionKind - for gvk := range knownTypes { - if objGVK.GroupKind() == gvk.GroupKind() { - gvks = append(gvks, gvk) - } - } - return gvks, nil -} - -// PartialImplementationError represents an error due to partial conversion -// implementation such as hub without spokes, multiple hubs or spokes without hub. -type PartialImplementationError struct { - gvk schema.GroupVersionKind - hubs []runtime.Object - nonSpokes []runtime.Object - spokes []runtime.Object -} - -func (e PartialImplementationError) Error() string { - if len(e.hubs) == 0 { - return fmt.Sprintf("no hub defined for gvk %s", e.gvk) - } - if len(e.hubs) > 1 { - return fmt.Sprintf("multiple(%d) hubs defined for group-kind '%s' ", - len(e.hubs), e.gvk.GroupKind()) - } - if len(e.nonSpokes) > 0 { - return fmt.Sprintf("%d inconvertible types detected for group-kind '%s'", - len(e.nonSpokes), e.gvk.GroupKind()) - } - return "" -} - -// isHub determines if passed-in object is a Hub or not. -func isHub(obj runtime.Object) bool { - _, yes := obj.(conversion.Hub) - return yes -} - -// isConvertible determines if passed-in object is a convertible. -func isConvertible(obj runtime.Object) bool { - _, yes := obj.(conversion.Convertible) - return yes -} - -// helper to construct error response. -func errored(err error) *apix.ConversionResponse { - return &apix.ConversionResponse{ - Result: metav1.Status{ - Status: metav1.StatusFailure, - Message: err.Error(), - }, - } -} diff --git a/vendor/sigs.k8s.io/controller-runtime/pkg/webhook/conversion/decoder.go b/vendor/sigs.k8s.io/controller-runtime/pkg/webhook/conversion/decoder.go deleted file mode 100644 index b6bb8bd938..0000000000 --- a/vendor/sigs.k8s.io/controller-runtime/pkg/webhook/conversion/decoder.go +++ /dev/null @@ -1,50 +0,0 @@ -/* -Copyright 2021 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package conversion - -import ( - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/runtime/serializer" -) - -// Decoder knows how to decode the contents of a CRD version conversion -// request into a concrete object. -// TODO(droot): consider reusing decoder from admission pkg for this. -type Decoder struct { - codecs serializer.CodecFactory -} - -// NewDecoder creates a Decoder given the runtime.Scheme -func NewDecoder(scheme *runtime.Scheme) *Decoder { - if scheme == nil { - panic("scheme should never be nil") - } - return &Decoder{codecs: serializer.NewCodecFactory(scheme)} -} - -// Decode decodes the inlined object. -func (d *Decoder) Decode(content []byte) (runtime.Object, *schema.GroupVersionKind, error) { - deserializer := d.codecs.UniversalDeserializer() - return deserializer.Decode(content, nil, nil) -} - -// DecodeInto decodes the inlined object in the into the passed-in runtime.Object. -func (d *Decoder) DecodeInto(content []byte, into runtime.Object) error { - deserializer := d.codecs.UniversalDeserializer() - return runtime.DecodeInto(deserializer, content, into) -}