mirror of https://github.com/knative/client.git
upgrade to latest dependencies (#1137)
Signed-off-by: Knative Automation <automation@knative.team>
This commit is contained in:
parent
ed4fa06e2e
commit
861f63d406
8
go.mod
8
go.mod
|
|
@ -22,11 +22,11 @@ require (
|
|||
k8s.io/cli-runtime v0.18.8
|
||||
k8s.io/client-go v11.0.1-0.20190805182717-6502b5e7b1b5+incompatible
|
||||
k8s.io/code-generator v0.18.12
|
||||
knative.dev/eventing v0.19.1-0.20201124020934-518010ed7378
|
||||
knative.dev/eventing v0.19.1-0.20201124193335-c7411ae08ea1
|
||||
knative.dev/hack v0.0.0-20201120192952-353db687ec5b
|
||||
knative.dev/networking v0.0.0-20201124014134-a79c9d045b05
|
||||
knative.dev/pkg v0.0.0-20201124023135-49e55c9eb816
|
||||
knative.dev/serving v0.19.1-0.20201124025434-f19b58586067
|
||||
knative.dev/networking v0.0.0-20201125013535-28c37e3cbe53
|
||||
knative.dev/pkg v0.0.0-20201124204235-3154117dcfaf
|
||||
knative.dev/serving v0.19.1-0.20201125001834-bddcc56f96ff
|
||||
sigs.k8s.io/yaml v1.2.0
|
||||
)
|
||||
|
||||
|
|
|
|||
17
go.sum
17
go.sum
|
|
@ -1221,27 +1221,28 @@ k8s.io/legacy-cloud-providers v0.18.8/go.mod h1:tgp4xYf6lvjrWnjQwTOPvWQE9IVqSBGP
|
|||
k8s.io/utils v0.0.0-20200324210504-a9aa75ae1b89/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew=
|
||||
k8s.io/utils v0.0.0-20200603063816-c1c6865ac451 h1:v8ud2Up6QK1lNOKFgiIVrZdMg7MpmSnvtrOieolJKoE=
|
||||
k8s.io/utils v0.0.0-20200603063816-c1c6865ac451/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
|
||||
knative.dev/caching v0.0.0-20201123014053-4019baeb5eb9/go.mod h1:sntT31v7vKbqLXV8CpLHPOSzPh46SmZKHvADs9Bb2Sc=
|
||||
knative.dev/eventing v0.19.1-0.20201124020934-518010ed7378 h1:PQbwuD5ndhRQFLDl4DVNai1aC0n05jtoL+KDiPRDMZo=
|
||||
knative.dev/eventing v0.19.1-0.20201124020934-518010ed7378/go.mod h1:Og0fBqu0B4l400fBzTv/rgZKtjLSsf8+brd4YKJ6obo=
|
||||
knative.dev/caching v0.0.0-20201124023036-dfa63c15d12a/go.mod h1:M2M5CzZ03W+aXjvz9XANACo8QCoCfT0Khsd6imqvw3g=
|
||||
knative.dev/eventing v0.19.1-0.20201124193335-c7411ae08ea1 h1:5Vw6ECqR7k2vhd1PGML5KGI/v6cSCYnJRFR9qpPJ9Wo=
|
||||
knative.dev/eventing v0.19.1-0.20201124193335-c7411ae08ea1/go.mod h1:Og0fBqu0B4l400fBzTv/rgZKtjLSsf8+brd4YKJ6obo=
|
||||
knative.dev/hack v0.0.0-20201112185459-01a34c573bd8 h1:RNbZsAjhswBPtl4C5C5gEFX5/GfWIOZQxfYD9DhkHdY=
|
||||
knative.dev/hack v0.0.0-20201112185459-01a34c573bd8/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI=
|
||||
knative.dev/hack v0.0.0-20201118155651-b31d3bb6bff9/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI=
|
||||
knative.dev/hack v0.0.0-20201119155951-11aa26c8eaf6/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI=
|
||||
knative.dev/hack v0.0.0-20201120192952-353db687ec5b h1:Lc+AKgwhAZUD98mN++qTHeeaP6FRmS8fcwc/rXkP8G0=
|
||||
knative.dev/hack v0.0.0-20201120192952-353db687ec5b/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI=
|
||||
knative.dev/networking v0.0.0-20201123172858-4ec5898ef753/go.mod h1:bWOUlIdZ3swi7zfm/BovM9UpJHcddS6dwD+sVN5xzYo=
|
||||
knative.dev/networking v0.0.0-20201124014134-a79c9d045b05 h1:7syeoKRw7l0il7kVpl/DEugBM8ndDDeK03yrqDAolGg=
|
||||
knative.dev/networking v0.0.0-20201124014134-a79c9d045b05/go.mod h1:9jAy7B2mMH/nEqBH79ucIxnWHXK4HF3K3PgyalkVCss=
|
||||
knative.dev/networking v0.0.0-20201125013535-28c37e3cbe53 h1:ZX9ObvdqHktEEy2LcHOTNb4LD67FKINIFSocdA9SIZg=
|
||||
knative.dev/networking v0.0.0-20201125013535-28c37e3cbe53/go.mod h1:w8PlQD3f4J2J3shFNdCYwUh3rzYBqEynohp0EVQX2tM=
|
||||
knative.dev/pkg v0.0.0-20201117221452-0fccc54273ed h1:4LNEFhvD2Ya4WgCD3SC1WGXz81bjEvQgbcpe5XACI3I=
|
||||
knative.dev/pkg v0.0.0-20201117221452-0fccc54273ed/go.mod h1:nxlh3CUvx6WBPr1WKD96AHxFZPD2UKRDo9RUp8ILTyQ=
|
||||
knative.dev/pkg v0.0.0-20201120183152-6a0e731e251a/go.mod h1:+H35jH64QU/7LiRs53AdqHAk19GOBpuNqCQpEQvjTn4=
|
||||
knative.dev/pkg v0.0.0-20201123172958-fea72c1c8e2f/go.mod h1:wXZqP8MXCxb51yNFlecA13BwG7Hk370SWDFWV4dx4ug=
|
||||
knative.dev/pkg v0.0.0-20201124023135-49e55c9eb816 h1:twVZmgBLLBaUUAVxxdPKZJzPief+izcV3boMc5P1xDY=
|
||||
knative.dev/pkg v0.0.0-20201124023135-49e55c9eb816/go.mod h1:wXZqP8MXCxb51yNFlecA13BwG7Hk370SWDFWV4dx4ug=
|
||||
knative.dev/pkg v0.0.0-20201124204235-3154117dcfaf h1:H5um6wZSd1Qmqqozr+/nHF2HyaMde6GNXM3+KbaYlJc=
|
||||
knative.dev/pkg v0.0.0-20201124204235-3154117dcfaf/go.mod h1:wXZqP8MXCxb51yNFlecA13BwG7Hk370SWDFWV4dx4ug=
|
||||
knative.dev/reconciler-test v0.0.0-20201123224957-57547e427baf/go.mod h1:YSs1y1rgnjs8w39/drLIOQbWvZUQwqApvd+EizO8UsA=
|
||||
knative.dev/serving v0.19.1-0.20201124025434-f19b58586067 h1:mswppzSxwwqkcy3zliLBpFpj/ynPVXy89Ai5ETHtXtY=
|
||||
knative.dev/serving v0.19.1-0.20201124025434-f19b58586067/go.mod h1:RoebgBVk+D9hv83yFaRG1pRsu3ujajdMIj7wpy/1eqc=
|
||||
knative.dev/serving v0.19.1-0.20201125001834-bddcc56f96ff h1:ki0I/iQH0MRxozIFH40iGVji6keYakBZq2Pm7Bkyknw=
|
||||
knative.dev/serving v0.19.1-0.20201125001834-bddcc56f96ff/go.mod h1:KdTOEfJP+mFMaoSRQRwSv1uAkg8Hcbtix6SkaXcNeCY=
|
||||
pgregory.net/rapid v0.3.3/go.mod h1:UYpPVyjFHzYBGHIxLFoupi8vwk6rXNzRY9OMvVxFIOU=
|
||||
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
|
||||
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
|
||||
|
|
|
|||
|
|
@ -493,7 +493,7 @@ func (c *Impl) processNextWorkItem() bool {
|
|||
if err != nil {
|
||||
status = falseString
|
||||
}
|
||||
c.statsReporter.ReportReconcile(time.Since(startTime), status)
|
||||
c.statsReporter.ReportReconcile(time.Since(startTime), status, key)
|
||||
|
||||
// We call Done here so the workqueue knows we have finished
|
||||
// processing this item. We also must remember to call Forget if
|
||||
|
|
|
|||
|
|
@ -25,10 +25,12 @@ import (
|
|||
"go.opencensus.io/stats/view"
|
||||
"go.opencensus.io/tag"
|
||||
"go.uber.org/zap"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
kubemetrics "k8s.io/client-go/tools/metrics"
|
||||
"k8s.io/client-go/util/workqueue"
|
||||
"knative.dev/pkg/metrics"
|
||||
"knative.dev/pkg/metrics/metricskey"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -47,6 +49,7 @@ var (
|
|||
// - characters are printable US-ASCII
|
||||
reconcilerTagKey = tag.MustNewKey("reconciler")
|
||||
successTagKey = tag.MustNewKey("success")
|
||||
NamespaceTagKey = tag.MustNewKey(metricskey.LabelNamespaceName)
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
|
@ -170,12 +173,12 @@ func init() {
|
|||
Description: "Number of reconcile operations",
|
||||
Measure: reconcileCountStat,
|
||||
Aggregation: view.Count(),
|
||||
TagKeys: []tag.Key{reconcilerTagKey, successTagKey},
|
||||
TagKeys: []tag.Key{reconcilerTagKey, successTagKey, NamespaceTagKey},
|
||||
}, {
|
||||
Description: "Latency of reconcile operations",
|
||||
Measure: reconcileLatencyStat,
|
||||
Aggregation: reconcileDistribution,
|
||||
TagKeys: []tag.Key{reconcilerTagKey, successTagKey},
|
||||
TagKeys: []tag.Key{reconcilerTagKey, successTagKey, NamespaceTagKey},
|
||||
}}
|
||||
views = append(views, wp.DefaultViews()...)
|
||||
views = append(views, rp.DefaultViews()...)
|
||||
|
|
@ -195,7 +198,7 @@ type StatsReporter interface {
|
|||
ReportQueueDepth(v int64) error
|
||||
|
||||
// ReportReconcile reports the count and latency metrics for a reconcile operation
|
||||
ReportReconcile(duration time.Duration, success string) error
|
||||
ReportReconcile(duration time.Duration, success string, key types.NamespacedName) error
|
||||
}
|
||||
|
||||
// Reporter holds cached metric objects to report metrics
|
||||
|
|
@ -237,11 +240,14 @@ func (r *reporter) ReportQueueDepth(v int64) error {
|
|||
}
|
||||
|
||||
// ReportReconcile reports the count and latency metrics for a reconcile operation
|
||||
func (r *reporter) ReportReconcile(duration time.Duration, success string) error {
|
||||
func (r *reporter) ReportReconcile(duration time.Duration, success string, key types.NamespacedName) error {
|
||||
ctx, err := tag.New(
|
||||
context.Background(),
|
||||
tag.Insert(reconcilerTagKey, r.reconciler),
|
||||
tag.Insert(successTagKey, success))
|
||||
tag.Insert(successTagKey, success),
|
||||
tag.Insert(NamespaceTagKey, key.Namespace),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,16 +20,12 @@ package test
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"knative.dev/pkg/test/flags"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"knative.dev/pkg/test/logging"
|
||||
"knative.dev/pkg/test/spoof"
|
||||
|
|
@ -37,107 +33,37 @@ import (
|
|||
|
||||
// RequestOption enables configuration of requests
|
||||
// when polling for endpoint states.
|
||||
type RequestOption func(*http.Request)
|
||||
type RequestOption = spoof.RequestOption
|
||||
|
||||
// WithHeader will add the provided headers to the request.
|
||||
func WithHeader(header http.Header) RequestOption {
|
||||
return func(r *http.Request) {
|
||||
if r.Header == nil {
|
||||
r.Header = header
|
||||
return
|
||||
}
|
||||
for key, values := range header {
|
||||
for _, value := range values {
|
||||
r.Header.Add(key, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// Deprecated: Use the spoof package version
|
||||
var WithHeader = spoof.WithHeader
|
||||
|
||||
// Retrying modifies a ResponseChecker to retry certain response codes.
|
||||
func Retrying(rc spoof.ResponseChecker, codes ...int) spoof.ResponseChecker {
|
||||
return func(resp *spoof.Response) (bool, error) {
|
||||
for _, code := range codes {
|
||||
if resp.StatusCode == code {
|
||||
// Returning (false, nil) causes SpoofingClient.Poll to retry.
|
||||
// sc.logger.Info("Retrying for code ", resp.StatusCode)
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
|
||||
// If we didn't match any retryable codes, invoke the ResponseChecker that we wrapped.
|
||||
return rc(resp)
|
||||
}
|
||||
}
|
||||
//
|
||||
// Deprecated: Use the spoof package version
|
||||
var Retrying = spoof.Retrying
|
||||
|
||||
// IsOneOfStatusCodes checks that the response code is equal to the given one.
|
||||
func IsOneOfStatusCodes(codes ...int) spoof.ResponseChecker {
|
||||
return func(resp *spoof.Response) (bool, error) {
|
||||
for _, code := range codes {
|
||||
if resp.StatusCode == code {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
return true, fmt.Errorf("status = %d %s, want one of: %v", resp.StatusCode, resp.Status, codes)
|
||||
}
|
||||
}
|
||||
//
|
||||
// Deprecated: Use the spoof package version
|
||||
var IsOneOfStatusCodes = spoof.IsOneOfStatusCodes
|
||||
|
||||
// IsStatusOK checks that the response code is a 200.
|
||||
func IsStatusOK(resp *spoof.Response) (bool, error) {
|
||||
return IsOneOfStatusCodes(http.StatusOK)(resp)
|
||||
}
|
||||
//
|
||||
// Deprecated: Use the spoof package version
|
||||
var IsStatusOK = spoof.IsStatusOK
|
||||
|
||||
// MatchesAllBodies checks that the *first* response body matches the "expected" body, otherwise failing.
|
||||
func MatchesAllBodies(all ...string) spoof.ResponseChecker {
|
||||
var m sync.Mutex
|
||||
// This helps with two things:
|
||||
// 1. we can use Equal on sets
|
||||
// 2. it will collapse the duplicates
|
||||
want := sets.NewString(all...)
|
||||
seen := make(sets.String, len(all))
|
||||
|
||||
return func(resp *spoof.Response) (bool, error) {
|
||||
bs := string(resp.Body)
|
||||
for expected := range want {
|
||||
if !strings.Contains(bs, expected) {
|
||||
// See if the next one matches.
|
||||
continue
|
||||
}
|
||||
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
seen.Insert(expected)
|
||||
|
||||
// Stop once we've seen them all.
|
||||
return want.Equal(seen), nil
|
||||
}
|
||||
|
||||
// Returning (true, err) causes SpoofingClient.Poll to fail.
|
||||
return true, fmt.Errorf("body = %s, want one of: %s", bs, all)
|
||||
}
|
||||
}
|
||||
//
|
||||
// Deprecated: Use the spoof package version
|
||||
var MatchesAllBodies = spoof.MatchesAllBodies
|
||||
|
||||
// MatchesBody checks that the *first* response body matches the "expected" body, otherwise failing.
|
||||
func MatchesBody(expected string) spoof.ResponseChecker {
|
||||
return func(resp *spoof.Response) (bool, error) {
|
||||
if !strings.Contains(string(resp.Body), expected) {
|
||||
// Returning (true, err) causes SpoofingClient.Poll to fail.
|
||||
return true, fmt.Errorf("body = %s, want: %s", string(resp.Body), expected)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// EventuallyMatchesBody checks that the response body *eventually* matches the expected body.
|
||||
// TODO(#1178): Delete me. We don't want to need this; we should be waiting for an appropriate Status instead.
|
||||
func EventuallyMatchesBody(expected string) spoof.ResponseChecker {
|
||||
return func(resp *spoof.Response) (bool, error) {
|
||||
// Returning (false, nil) causes SpoofingClient.Poll to retry.
|
||||
return strings.Contains(string(resp.Body), expected), nil
|
||||
}
|
||||
}
|
||||
//
|
||||
// Deprecated: Use the spoof package version
|
||||
var MatchesBody = spoof.MatchesBody
|
||||
|
||||
// MatchesAllOf combines multiple ResponseCheckers to one ResponseChecker with a logical AND. The
|
||||
// checkers are executed in order. The first function to trigger an error or a retry will short-circuit
|
||||
|
|
@ -147,14 +73,16 @@ func EventuallyMatchesBody(expected string) spoof.ResponseChecker {
|
|||
// MatchesAllOf(IsStatusOK, MatchesBody("test"))
|
||||
//
|
||||
// The MatchesBody check will only be executed after the IsStatusOK has passed.
|
||||
func MatchesAllOf(checkers ...spoof.ResponseChecker) spoof.ResponseChecker {
|
||||
//
|
||||
// Deprecated: Use the spoof package version
|
||||
var MatchesAllOf = spoof.MatchesAllOf
|
||||
|
||||
// EventuallyMatchesBody checks that the response body *eventually* matches the expected body.
|
||||
// TODO(#1178): Delete me. We don't want to need this; we should be waiting for an appropriate Status instead.
|
||||
func EventuallyMatchesBody(expected string) spoof.ResponseChecker {
|
||||
return func(resp *spoof.Response) (bool, error) {
|
||||
for _, checker := range checkers {
|
||||
if done, err := checker(resp); err != nil || !done {
|
||||
return done, err
|
||||
}
|
||||
}
|
||||
return true, nil
|
||||
// Returning (false, nil) causes SpoofingClient.Poll to retry.
|
||||
return strings.Contains(string(resp.Body), expected), nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -193,24 +121,16 @@ func WaitForEndpointStateWithTimeout(
|
|||
resolvable bool,
|
||||
timeout time.Duration,
|
||||
opts ...interface{}) (*spoof.Response, error) {
|
||||
defer logging.GetEmitableSpan(ctx, "WaitForEndpointState/"+desc).End()
|
||||
|
||||
if url.Scheme == "" || url.Host == "" {
|
||||
return nil, fmt.Errorf("invalid URL: %q", url.String())
|
||||
}
|
||||
|
||||
req, err := http.NewRequest(http.MethodGet, url.String(), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tOpts []spoof.TransportOption
|
||||
var rOpts []spoof.RequestOption
|
||||
|
||||
for _, opt := range opts {
|
||||
rOpt, ok := opt.(RequestOption)
|
||||
if ok {
|
||||
rOpt(req)
|
||||
} else if tOpt, ok := opt.(spoof.TransportOption); ok {
|
||||
tOpts = append(tOpts, tOpt)
|
||||
switch o := opt.(type) {
|
||||
case spoof.RequestOption:
|
||||
rOpts = append(rOpts, o)
|
||||
case spoof.TransportOption:
|
||||
tOpts = append(tOpts, o)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -220,5 +140,5 @@ func WaitForEndpointStateWithTimeout(
|
|||
}
|
||||
client.RequestTimeout = timeout
|
||||
|
||||
return client.Poll(req, inState)
|
||||
return client.WaitForEndpointState(ctx, url, inState, desc, rOpts...)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
Copyright 2020 The Knative 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 spoof
|
||||
|
||||
import "net/http"
|
||||
|
||||
// RequestOption enables configuration of requests
|
||||
// when polling for endpoint states.
|
||||
type RequestOption func(*http.Request)
|
||||
|
||||
// WithHeader will add the provided headers to the request.
|
||||
func WithHeader(header http.Header) RequestOption {
|
||||
return func(r *http.Request) {
|
||||
if r.Header == nil {
|
||||
r.Header = header
|
||||
return
|
||||
}
|
||||
for key, values := range header {
|
||||
for _, value := range values {
|
||||
r.Header.Add(key, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,121 @@
|
|||
/*
|
||||
Copyright 2020 The Knative 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 spoof
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
)
|
||||
|
||||
// MatchesBody checks that the *first* response body matches the "expected" body, otherwise failing.
|
||||
func MatchesBody(expected string) ResponseChecker {
|
||||
return func(resp *Response) (bool, error) {
|
||||
if !strings.Contains(string(resp.Body), expected) {
|
||||
// Returning (true, err) causes SpoofingClient.Poll to fail.
|
||||
return true, fmt.Errorf("body = %s, want: %s", string(resp.Body), expected)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// MatchesAllOf combines multiple ResponseCheckers to one ResponseChecker with a logical AND. The
|
||||
// checkers are executed in order. The first function to trigger an error or a retry will short-circuit
|
||||
// the other functions (they will not be executed).
|
||||
//
|
||||
// This is useful for combining a body with a status check like:
|
||||
// MatchesAllOf(IsStatusOK, MatchesBody("test"))
|
||||
//
|
||||
// The MatchesBody check will only be executed after the IsStatusOK has passed.
|
||||
func MatchesAllOf(checkers ...ResponseChecker) ResponseChecker {
|
||||
return func(resp *Response) (bool, error) {
|
||||
for _, checker := range checkers {
|
||||
if done, err := checker(resp); err != nil || !done {
|
||||
return done, err
|
||||
}
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// MatchesAllBodies checks that the *first* response body matches the "expected" body, otherwise failing.
|
||||
func MatchesAllBodies(all ...string) ResponseChecker {
|
||||
var m sync.Mutex
|
||||
// This helps with two things:
|
||||
// 1. we can use Equal on sets
|
||||
// 2. it will collapse the duplicates
|
||||
want := sets.NewString(all...)
|
||||
seen := make(sets.String, len(all))
|
||||
|
||||
return func(resp *Response) (bool, error) {
|
||||
bs := string(resp.Body)
|
||||
for expected := range want {
|
||||
if !strings.Contains(bs, expected) {
|
||||
// See if the next one matches.
|
||||
continue
|
||||
}
|
||||
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
seen.Insert(expected)
|
||||
|
||||
// Stop once we've seen them all.
|
||||
return want.Equal(seen), nil
|
||||
}
|
||||
|
||||
// Returning (true, err) causes SpoofingClient.Poll to fail.
|
||||
return true, fmt.Errorf("body = %s, want one of: %s", bs, all)
|
||||
}
|
||||
}
|
||||
|
||||
// IsStatusOK checks that the response code is a 200.
|
||||
func IsStatusOK(resp *Response) (bool, error) {
|
||||
return IsOneOfStatusCodes(http.StatusOK)(resp)
|
||||
}
|
||||
|
||||
// IsOneOfStatusCodes checks that the response code is equal to the given one.
|
||||
func IsOneOfStatusCodes(codes ...int) ResponseChecker {
|
||||
return func(resp *Response) (bool, error) {
|
||||
for _, code := range codes {
|
||||
if resp.StatusCode == code {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
return true, fmt.Errorf("status = %d %s, want one of: %v", resp.StatusCode, resp.Status, codes)
|
||||
}
|
||||
}
|
||||
|
||||
// Retrying modifies a ResponseChecker to retry certain response codes.
|
||||
func Retrying(rc ResponseChecker, codes ...int) ResponseChecker {
|
||||
return func(resp *Response) (bool, error) {
|
||||
for _, code := range codes {
|
||||
if resp.StatusCode == code {
|
||||
// Returning (false, nil) causes SpoofingClient.Poll to retry.
|
||||
// sc.logger.Info("Retrying for code ", resp.StatusCode)
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
|
||||
// If we didn't match any retryable codes, invoke the ResponseChecker that we wrapped.
|
||||
return rc(resp)
|
||||
}
|
||||
}
|
||||
|
|
@ -26,6 +26,7 @@ import (
|
|||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
|
|
@ -245,3 +246,28 @@ func (sc *SpoofingClient) logZipkinTrace(spoofResp *Response) {
|
|||
|
||||
sc.Logf("%s", json)
|
||||
}
|
||||
|
||||
func (sc *SpoofingClient) WaitForEndpointState(
|
||||
ctx context.Context,
|
||||
url *url.URL,
|
||||
inState ResponseChecker,
|
||||
desc string,
|
||||
opts ...RequestOption) (*Response, error) {
|
||||
|
||||
defer logging.GetEmitableSpan(ctx, "WaitForEndpointState/"+desc).End()
|
||||
|
||||
if url.Scheme == "" || url.Host == "" {
|
||||
return nil, fmt.Errorf("invalid URL: %q", url.String())
|
||||
}
|
||||
|
||||
req, err := http.NewRequest(http.MethodGet, url.String(), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, opt := range opts {
|
||||
opt(req)
|
||||
}
|
||||
|
||||
return sc.Poll(req, inState)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -843,7 +843,7 @@ k8s.io/kube-openapi/pkg/util/sets
|
|||
k8s.io/utils/buffer
|
||||
k8s.io/utils/integer
|
||||
k8s.io/utils/trace
|
||||
# knative.dev/eventing v0.19.1-0.20201124020934-518010ed7378
|
||||
# knative.dev/eventing v0.19.1-0.20201124193335-c7411ae08ea1
|
||||
## explicit
|
||||
knative.dev/eventing/pkg/apis/config
|
||||
knative.dev/eventing/pkg/apis/configs
|
||||
|
|
@ -876,12 +876,12 @@ knative.dev/eventing/pkg/client/clientset/versioned/typed/sources/v1alpha2/fake
|
|||
# knative.dev/hack v0.0.0-20201120192952-353db687ec5b
|
||||
## explicit
|
||||
knative.dev/hack
|
||||
# knative.dev/networking v0.0.0-20201124014134-a79c9d045b05
|
||||
# knative.dev/networking v0.0.0-20201125013535-28c37e3cbe53
|
||||
## explicit
|
||||
knative.dev/networking/pkg
|
||||
knative.dev/networking/pkg/apis/networking
|
||||
knative.dev/networking/pkg/apis/networking/v1alpha1
|
||||
# knative.dev/pkg v0.0.0-20201124023135-49e55c9eb816
|
||||
# knative.dev/pkg v0.0.0-20201124204235-3154117dcfaf
|
||||
## explicit
|
||||
knative.dev/pkg/apis
|
||||
knative.dev/pkg/apis/duck
|
||||
|
|
@ -921,7 +921,7 @@ knative.dev/pkg/tracing/config
|
|||
knative.dev/pkg/tracing/propagation
|
||||
knative.dev/pkg/tracing/propagation/tracecontextb3
|
||||
knative.dev/pkg/tracker
|
||||
# knative.dev/serving v0.19.1-0.20201124025434-f19b58586067
|
||||
# knative.dev/serving v0.19.1-0.20201125001834-bddcc56f96ff
|
||||
## explicit
|
||||
knative.dev/serving/pkg/apis/autoscaling
|
||||
knative.dev/serving/pkg/apis/autoscaling/v1alpha1
|
||||
|
|
|
|||
Loading…
Reference in New Issue