From f9a94908b87ce2a865bbf800be549625efd140f6 Mon Sep 17 00:00:00 2001 From: Matt Moore Date: Tue, 31 Mar 2020 07:44:51 -0700 Subject: [PATCH] [master] Auto-update dependencies (#239) Produced via: `./hack/update-deps.sh --upgrade && ./hack/update-codegen.sh` /assign n3wscott vagababov /cc n3wscott vagababov --- Gopkg.lock | 8 ++-- vendor/knative.dev/pkg/Gopkg.lock | 6 +-- vendor/knative.dev/pkg/Gopkg.toml | 2 +- .../pkg/injection/sharedmain/main.go | 41 +++++++++++-------- vendor/knative.dev/pkg/webhook/admission.go | 24 ++++++++++- .../pkg/webhook/configmaps/configmaps.go | 3 ++ .../defaulting/defaulting.go | 3 ++ .../validation/validation.go | 3 ++ vendor/knative.dev/pkg/webhook/webhook.go | 27 ++++++++---- .../test-infra/scripts/presubmit-tests.sh | 4 +- 10 files changed, 84 insertions(+), 37 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index cb628514..afff1ec0 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -966,7 +966,7 @@ [[projects]] branch = "master" - digest = "1:664207d75dbcaeab206d93b3dcd8098c59e3b6b21378af02d686579e491fc859" + digest = "1:18f4c5453f19fef868e3da19f815840517c4bfa28e15fb2cccd504a9b96ce68d" name = "knative.dev/pkg" packages = [ "apis", @@ -986,18 +986,18 @@ "reconciler", ] pruneopts = "T" - revision = "8a6d25b30970038d1e24ddf5f6e0cec129c9564c" + revision = "e2ee5bed78d74604ed87dcb761a6f6e10a2e355c" [[projects]] branch = "master" - digest = "1:2987a1db00b983af9e5d5281639a754fb6449eef01e6a375894829eaec17cb2a" + digest = "1:41da78d06d64a1eb47a1d3f8209d33af386fa8f22d1b04b25825ae5cd187be1d" name = "knative.dev/test-infra" packages = [ "scripts", "tools/dep-collector", ] pruneopts = "UT" - revision = "9a6c4b1d41ce980537cebe2b34c4b8c92fbd2b47" + revision = "030e4e29cb8ba9502a06b667b1450f6a725371b1" [[projects]] digest = "1:8730e0150dfb2b7e173890c8b9868e7a273082ef8e39f4940e3506a481cf895c" diff --git a/vendor/knative.dev/pkg/Gopkg.lock b/vendor/knative.dev/pkg/Gopkg.lock index a15b7677..ca503115 100644 --- a/vendor/knative.dev/pkg/Gopkg.lock +++ b/vendor/knative.dev/pkg/Gopkg.lock @@ -918,12 +918,12 @@ version = "v0.9.1" [[projects]] - digest = "1:accc3bfe4e404aa53ac3621470e7cf9fce1efe48f0fabcfe6d12a72579d9d91f" + digest = "1:d9b9ac6943a512737f76bf3d61b08d97121c66686bc02ffc231313563230b468" name = "gopkg.in/yaml.v2" packages = ["."] pruneopts = "NUT" - revision = "f221b8435cfb71e54062f6c6e99e9ade30b124d5" - version = "v2.2.4" + revision = "53403b58ad1b561927d19068c655246f2db79d48" + version = "v2.2.8" [[projects]] digest = "1:d77b48cc0ea74f3edbc8e0515a0ce2fa2154eb414137dd4fb5a642a73296d403" diff --git a/vendor/knative.dev/pkg/Gopkg.toml b/vendor/knative.dev/pkg/Gopkg.toml index 436f8a99..f008b8dd 100644 --- a/vendor/knative.dev/pkg/Gopkg.toml +++ b/vendor/knative.dev/pkg/Gopkg.toml @@ -50,7 +50,7 @@ required = [ [[override]] name = "gopkg.in/yaml.v2" - version = "v2.2.4" + version = "v2.2.8" [[override]] name = "github.com/json-iterator/go" diff --git a/vendor/knative.dev/pkg/injection/sharedmain/main.go b/vendor/knative.dev/pkg/injection/sharedmain/main.go index 0eb16ecd..4165acbd 100644 --- a/vendor/knative.dev/pkg/injection/sharedmain/main.go +++ b/vendor/knative.dev/pkg/injection/sharedmain/main.go @@ -232,6 +232,26 @@ func WebhookMainWithConfig(ctx context.Context, component string, cfg *rest.Conf WatchLoggingConfigOrDie(ctx, cmw, logger, atomicLevel, component) WatchObservabilityConfigOrDie(ctx, cmw, profilingHandler, logger, component) + eg, egCtx := errgroup.WithContext(ctx) + eg.Go(profilingServer.ListenAndServe) + + // If we have one or more admission controllers, then start the webhook + // and pass them in. + var wh *webhook.Webhook + var err error + if len(webhooks) > 0 { + // Register webhook metrics + webhook.RegisterMetrics() + + wh, err = webhook.New(ctx, webhooks) + if err != nil { + logger.Fatalw("Failed to create webhook", zap.Error(err)) + } + eg.Go(func() error { + return wh.Run(ctx.Done()) + }) + } + logger.Info("Starting configuration manager...") if err := cmw.Start(ctx.Done()); err != nil { logger.Fatalw("Failed to start configuration manager", zap.Error(err)) @@ -240,27 +260,12 @@ func WebhookMainWithConfig(ctx context.Context, component string, cfg *rest.Conf if err := controller.StartInformers(ctx.Done(), informers...); err != nil { logger.Fatalw("Failed to start informers", zap.Error(err)) } + if wh != nil { + wh.InformersHaveSynced() + } logger.Info("Starting controllers...") go controller.StartAll(ctx.Done(), controllers...) - eg, egCtx := errgroup.WithContext(ctx) - eg.Go(profilingServer.ListenAndServe) - - // If we have one or more admission controllers, then start the webhook - // and pass them in. - if len(webhooks) > 0 { - // Register webhook metrics - webhook.RegisterMetrics() - - wh, err := webhook.New(ctx, webhooks) - if err != nil { - logger.Fatalw("Failed to create webhook", zap.Error(err)) - } - eg.Go(func() error { - return wh.Run(ctx.Done()) - }) - } - // This will block until either a signal arrives or one of the grouped functions // returns an error. <-egCtx.Done() diff --git a/vendor/knative.dev/pkg/webhook/admission.go b/vendor/knative.dev/pkg/webhook/admission.go index 4bcd6483..1e50b588 100644 --- a/vendor/knative.dev/pkg/webhook/admission.go +++ b/vendor/knative.dev/pkg/webhook/admission.go @@ -39,6 +39,14 @@ type AdmissionController interface { Admit(context.Context, *admissionv1beta1.AdmissionRequest) *admissionv1beta1.AdmissionResponse } +// StatelessAdmissionController is implemented by AdmissionControllers where Admit may be safely +// called before informers have finished syncing. This is implemented by inlining +// StatelessAdmissionImpl in your Go type. +type StatelessAdmissionController interface { + // A silly name that should avoid collisions. + ThisTypeDoesNotDependOnInformerState() +} + // MakeErrorStatus creates an 'BadRequest' error AdmissionResponse func MakeErrorStatus(reason string, args ...interface{}) *admissionv1beta1.AdmissionResponse { result := apierrors.NewBadRequest(fmt.Sprintf(reason, args...)).Status() @@ -48,8 +56,17 @@ func MakeErrorStatus(reason string, args ...interface{}) *admissionv1beta1.Admis } } -func admissionHandler(rootLogger *zap.SugaredLogger, stats StatsReporter, c AdmissionController) http.HandlerFunc { +func admissionHandler(rootLogger *zap.SugaredLogger, stats StatsReporter, c AdmissionController, synced <-chan struct{}) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + if _, ok := c.(StatelessAdmissionController); ok { + // Stateless admission controllers do not require Informers to have + // finished syncing before Admit is called. + } else { + // Don't allow admission control requests through until we have been + // notified that informers have been synchronized. + <-synced + } + var ttStart = time.Now() logger := rootLogger logger.Infof("Webhook ServeHTTP request=%#v", r) @@ -92,3 +109,8 @@ func admissionHandler(rootLogger *zap.SugaredLogger, stats StatsReporter, c Admi } } } + +// Inline this type to implement StatelessAdmissionController. +type StatelessAdmissionImpl struct{} + +func (sai StatelessAdmissionImpl) ThisTypeDoesNotDependOnInformerState() {} diff --git a/vendor/knative.dev/pkg/webhook/configmaps/configmaps.go b/vendor/knative.dev/pkg/webhook/configmaps/configmaps.go index be28c770..f4805f8c 100644 --- a/vendor/knative.dev/pkg/webhook/configmaps/configmaps.go +++ b/vendor/knative.dev/pkg/webhook/configmaps/configmaps.go @@ -43,6 +43,8 @@ import ( // reconciler implements the AdmissionController for ConfigMaps type reconciler struct { + webhook.StatelessAdmissionImpl + name string path string constructors map[string]reflect.Value @@ -56,6 +58,7 @@ type reconciler struct { var _ controller.Reconciler = (*reconciler)(nil) var _ webhook.AdmissionController = (*reconciler)(nil) +var _ webhook.StatelessAdmissionController = (*reconciler)(nil) // Reconcile implements controller.Reconciler func (ac *reconciler) Reconcile(ctx context.Context, key string) error { diff --git a/vendor/knative.dev/pkg/webhook/resourcesemantics/defaulting/defaulting.go b/vendor/knative.dev/pkg/webhook/resourcesemantics/defaulting/defaulting.go index 0b1c129b..3eb7a8ac 100644 --- a/vendor/knative.dev/pkg/webhook/resourcesemantics/defaulting/defaulting.go +++ b/vendor/knative.dev/pkg/webhook/resourcesemantics/defaulting/defaulting.go @@ -50,6 +50,8 @@ var errMissingNewObject = errors.New("the new object may not be nil") // reconciler implements the AdmissionController for resources type reconciler struct { + webhook.StatelessAdmissionImpl + name string path string handlers map[schema.GroupVersionKind]resourcesemantics.GenericCRD @@ -66,6 +68,7 @@ type reconciler struct { var _ controller.Reconciler = (*reconciler)(nil) var _ webhook.AdmissionController = (*reconciler)(nil) +var _ webhook.StatelessAdmissionController = (*reconciler)(nil) // Reconcile implements controller.Reconciler func (ac *reconciler) Reconcile(ctx context.Context, key string) error { diff --git a/vendor/knative.dev/pkg/webhook/resourcesemantics/validation/validation.go b/vendor/knative.dev/pkg/webhook/resourcesemantics/validation/validation.go index f394c396..80f7622a 100644 --- a/vendor/knative.dev/pkg/webhook/resourcesemantics/validation/validation.go +++ b/vendor/knative.dev/pkg/webhook/resourcesemantics/validation/validation.go @@ -48,6 +48,8 @@ var errMissingNewObject = errors.New("the new object may not be nil") // reconciler implements the AdmissionController for resources type reconciler struct { + webhook.StatelessAdmissionImpl + name string path string handlers map[schema.GroupVersionKind]resourcesemantics.GenericCRD @@ -64,6 +66,7 @@ type reconciler struct { var _ controller.Reconciler = (*reconciler)(nil) var _ webhook.AdmissionController = (*reconciler)(nil) +var _ webhook.StatelessAdmissionController = (*reconciler)(nil) // Reconcile implements controller.Reconciler func (ac *reconciler) Reconcile(ctx context.Context, key string) error { diff --git a/vendor/knative.dev/pkg/webhook/webhook.go b/vendor/knative.dev/pkg/webhook/webhook.go index ec272a9c..99cb48d0 100644 --- a/vendor/knative.dev/pkg/webhook/webhook.go +++ b/vendor/knative.dev/pkg/webhook/webhook.go @@ -65,6 +65,9 @@ type Webhook struct { Options Options Logger *zap.SugaredLogger + // synced is function that is called when the informers have been synced. + synced context.CancelFunc + mux http.ServeMux secretlister corelisters.SecretLister } @@ -105,11 +108,14 @@ func New( opts.StatsReporter = reporter } + syncCtx, cancel := context.WithCancel(context.Background()) + webhook = &Webhook{ Client: client, Options: *opts, secretlister: secretInformer.Lister(), Logger: logger, + synced: cancel, } webhook.mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { @@ -117,26 +123,31 @@ func New( }) for _, controller := range controllers { - var handler http.Handler - var path string - switch c := controller.(type) { case AdmissionController: - handler = admissionHandler(logger, opts.StatsReporter, c) - path = c.Path() + handler := admissionHandler(logger, opts.StatsReporter, c, syncCtx.Done()) + webhook.mux.Handle(c.Path(), handler) + case ConversionController: - handler = conversionHandler(logger, opts.StatsReporter, c) - path = c.Path() + handler := conversionHandler(logger, opts.StatsReporter, c) + webhook.mux.Handle(c.Path(), handler) + default: return nil, fmt.Errorf("unknown webhook controller type: %T", controller) } - webhook.mux.Handle(path, handler) } return } +// InformersHaveSynced is called when the informers have all been synced, which allows any outstanding +// admission webhooks through. +func (wh *Webhook) InformersHaveSynced() { + wh.synced() + wh.Logger.Info("Informers have been synced, unblocking admission webhooks.") +} + // Run implements the admission controller run loop. func (wh *Webhook) Run(stop <-chan struct{}) error { logger := wh.Logger diff --git a/vendor/knative.dev/test-infra/scripts/presubmit-tests.sh b/vendor/knative.dev/test-infra/scripts/presubmit-tests.sh index 11b09a68..b038bfdc 100755 --- a/vendor/knative.dev/test-infra/scripts/presubmit-tests.sh +++ b/vendor/knative.dev/test-infra/scripts/presubmit-tests.sh @@ -28,7 +28,7 @@ readonly PRESUBMIT_TEST_FAIL_FAST=${PRESUBMIT_TEST_FAIL_FAST:-0} readonly NO_PRESUBMIT_FILES=(\.png \.gitignore \.gitattributes ^OWNERS ^OWNERS_ALIASES ^AUTHORS) # Flag if this is a presubmit run or not. -[[ IS_PROW && -n "${PULL_PULL_SHA}" ]] && IS_PRESUBMIT=1 || IS_PRESUBMIT=0 +(( IS_PROW )) && [[ -n "${PULL_PULL_SHA}" ]] && IS_PRESUBMIT=1 || IS_PRESUBMIT=0 readonly IS_PRESUBMIT # List of changed files on presubmit, LF separated. @@ -362,7 +362,7 @@ function main() { local failed=0 - if [[ ${#TESTS_TO_RUN[@]} > 0 ]]; then + if [[ ${#TESTS_TO_RUN[@]} -gt 0 ]]; then if (( RUN_BUILD_TESTS || RUN_UNIT_TESTS || RUN_INTEGRATION_TESTS )); then abort "--run-test must be used alone" fi