Auto-update dependencies (#194)

Produced via:
  `dep ensure -update knative.dev/test-infra knative.dev/pkg`
/assign n3wscott
/cc n3wscott
This commit is contained in:
Matt Moore 2020-02-03 08:15:29 -08:00 committed by GitHub
parent 1814fc9af6
commit f07214572b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 144 additions and 55 deletions

6
Gopkg.lock generated
View File

@ -966,7 +966,7 @@
[[projects]]
branch = "master"
digest = "1:eb75525bd4eb16133b648d1bbaa90e5eae2c10b42c97ae46b730c923ab799911"
digest = "1:107ee62154c011274e913c95b410fffde1c9a7ebb4e972a1428f4927a4f8afe6"
name = "knative.dev/pkg"
packages = [
"apis",
@ -985,7 +985,7 @@
"metrics/metricskey",
]
pruneopts = "T"
revision = "446f2e9f2cabb9a8249fad2cb19d92a0f918fae0"
revision = "d5698e90e262503c568a6abc645a0f34dcec385f"
[[projects]]
branch = "master"
@ -996,7 +996,7 @@
"tools/dep-collector",
]
pruneopts = "UT"
revision = "ae2eca5b05181add212724579f1d85d3b104cdd7"
revision = "25ea2a3bc5b89b01ebd564ee53bb737b2c4105e0"
[[projects]]
digest = "1:8730e0150dfb2b7e173890c8b9868e7a273082ef8e39f4940e3506a481cf895c"

View File

@ -9,3 +9,6 @@
# Temporary output of build tools
bazel-*
*.out
# Emacs files
*~

4
vendor/knative.dev/pkg/Gopkg.lock generated vendored
View File

@ -1323,14 +1323,14 @@
[[projects]]
branch = "master"
digest = "1:f0fb577e7a666886e560755c78e19b56b23303575677a9beca899316eb6a137c"
digest = "1:fdc3106893e9ad75a8615d1326df00899c519ea71684092b4a10b3260f3c0c15"
name = "knative.dev/test-infra"
packages = [
"scripts",
"tools/dep-collector",
]
pruneopts = "UT"
revision = "5779f9c9458d0a85f734c0cad43c1510aa00b498"
revision = "ae2eca5b05181add212724579f1d85d3b104cdd7"
[[projects]]
digest = "1:8730e0150dfb2b7e173890c8b9868e7a273082ef8e39f4940e3506a481cf895c"

View File

@ -19,7 +19,6 @@ package v1
import (
"context"
corev1 "k8s.io/api/core/v1"
"knative.dev/pkg/apis"
)
@ -27,7 +26,7 @@ import (
type Destination struct {
// Ref points to an Addressable.
// +optional
Ref *corev1.ObjectReference `json:"ref,omitempty"`
Ref *KnativeReference `json:"ref,omitempty"`
// URI can be an absolute URL(non-empty scheme and non-empty host) pointing to the target or a relative URI. Relative URIs will be resolved using the base URI retrieved from Ref.
// +optional
@ -38,56 +37,41 @@ func (dest *Destination) Validate(ctx context.Context) *apis.FieldError {
if dest == nil {
return nil
}
return ValidateDestination(*dest).ViaField(apis.CurrentField)
return ValidateDestination(ctx, *dest).ViaField(apis.CurrentField)
}
// ValidateDestination validates Destination.
func ValidateDestination(dest Destination) *apis.FieldError {
var ref *corev1.ObjectReference
if dest.Ref != nil {
ref = dest.Ref
}
if ref == nil && dest.URI == nil {
func ValidateDestination(ctx context.Context, dest Destination) *apis.FieldError {
ref := dest.Ref
uri := dest.URI
if ref == nil && uri == nil {
return apis.ErrGeneric("expected at least one, got none", "ref", "uri")
}
if ref != nil && dest.URI != nil && dest.URI.URL().IsAbs() {
if ref != nil && uri != nil && uri.URL().IsAbs() {
return apis.ErrGeneric("Absolute URI is not allowed when Ref or [apiVersion, kind, name] is present", "[apiVersion, kind, name]", "ref", "uri")
}
// IsAbs() check whether the URL has a non-empty scheme. Besides the non-empty scheme, we also require dest.URI has a non-empty host
if ref == nil && dest.URI != nil && (!dest.URI.URL().IsAbs() || dest.URI.Host == "") {
// IsAbs() check whether the URL has a non-empty scheme. Besides the non-empty scheme, we also require uri has a non-empty host
if ref == nil && uri != nil && (!uri.URL().IsAbs() || uri.Host == "") {
return apis.ErrInvalidValue("Relative URI is not allowed when Ref and [apiVersion, kind, name] is absent", "uri")
}
if ref != nil && dest.URI == nil {
if dest.Ref != nil {
return validateDestinationRef(*ref).ViaField("ref")
}
if ref != nil && uri == nil {
return ref.Validate(ctx).ViaField("ref")
}
return nil
}
// GetRef gets the ObjectReference from this Destination, if one is present. If no ref is present,
// GetRef gets the KnativeReference from this Destination, if one is present. If no ref is present,
// then nil is returned.
func (dest *Destination) GetRef() *corev1.ObjectReference {
func (dest *Destination) GetRef() *KnativeReference {
if dest == nil {
return nil
}
return dest.Ref
}
func validateDestinationRef(ref corev1.ObjectReference) *apis.FieldError {
// Check the object.
var errs *apis.FieldError
// Required Fields
if ref.Name == "" {
errs = errs.Also(apis.ErrMissingField("name"))
func (d *Destination) SetDefaults(ctx context.Context) {
if d.Ref != nil && d.Ref.Namespace == "" {
d.Ref.Namespace = apis.ParentMeta(ctx).Namespace
}
if ref.APIVersion == "" {
errs = errs.Also(apis.ErrMissingField("apiVersion"))
}
if ref.Kind == "" {
errs = errs.Also(apis.ErrMissingField("kind"))
}
return errs
}

View File

@ -0,0 +1,70 @@
/*
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 v1
import (
"context"
"knative.dev/pkg/apis"
)
// KnativeReference contains enough information to refer to another object.
// It's a trimmed down version of corev1.ObjectReference.
type KnativeReference struct {
// Kind of the referent.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
Kind string `json:"kind"`
// Namespace of the referent.
// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/
// This is optional field, it gets defaulted to the object holding it if left out.
// +optional
Namespace string `json:"namespace,omitempty"`
// Name of the referent.
// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
Name string `json:"name"`
// API version of the referent.
APIVersion string `json:"apiVersion"`
}
func (kr *KnativeReference) Validate(ctx context.Context) *apis.FieldError {
var errs *apis.FieldError
if kr == nil {
errs = errs.Also(apis.ErrMissingField("name"))
errs = errs.Also(apis.ErrMissingField("apiVersion"))
errs = errs.Also(apis.ErrMissingField("kind"))
return errs
}
if kr.Name == "" {
errs = errs.Also(apis.ErrMissingField("name"))
}
if kr.APIVersion == "" {
errs = errs.Also(apis.ErrMissingField("apiVersion"))
}
if kr.Kind == "" {
errs = errs.Also(apis.ErrMissingField("kind"))
}
return errs
}
func (kr *KnativeReference) SetDefaults(ctx context.Context) {
if kr.Namespace == "" {
kr.Namespace = apis.ParentMeta(ctx).Namespace
}
}

View File

@ -21,7 +21,6 @@ limitations under the License.
package v1
import (
corev1 "k8s.io/api/core/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
apis "knative.dev/pkg/apis"
)
@ -178,7 +177,7 @@ func (in *Destination) DeepCopyInto(out *Destination) {
*out = *in
if in.Ref != nil {
in, out := &in.Ref, &out.Ref
*out = new(corev1.ObjectReference)
*out = new(KnativeReference)
**out = **in
}
if in.URI != nil {
@ -259,6 +258,22 @@ func (in *KResourceList) DeepCopyObject() runtime.Object {
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *KnativeReference) DeepCopyInto(out *KnativeReference) {
*out = *in
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KnativeReference.
func (in *KnativeReference) DeepCopy() *KnativeReference {
if in == nil {
return nil
}
out := new(KnativeReference)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *PodSpecable) DeepCopyInto(out *PodSpecable) {
*out = *in

View File

@ -24,7 +24,7 @@ set -o pipefail
cd ${ROOT_DIR}
# Ensure we have everything we need under vendor/
dep ensure
dep ensure $@
rm -rf $(find vendor/ -name 'OWNERS')
rm -rf $(find vendor/ -name '*_test.go')

View File

@ -84,7 +84,7 @@ type metricsConfig struct {
// recorder provides a hook for performing custom transformations before
// writing the metrics to the stats.RecordWithOptions interface.
recorder func(context.Context, stats.Measurement, ...stats.Options) error
recorder func(context.Context, []stats.Measurement, ...stats.Options) error
// ---- OpenCensus specific below ----
// collectorAddress is the address of the collector, if not `localhost:55678`
@ -144,13 +144,13 @@ func NewStackdriverClientConfigFromMap(config map[string]string) *StackdriverCli
}
}
// Record applies the `ros` Options to `ms` and then records the resulting
// record applies the `ros` Options to each measurement in `mss` and then records the resulting
// measurements in the metricsConfig's designated backend.
func (mc *metricsConfig) Record(ctx context.Context, ms stats.Measurement, ros ...stats.Options) error {
func (mc *metricsConfig) record(ctx context.Context, mss []stats.Measurement, ros ...stats.Options) error {
if mc == nil || mc.recorder == nil {
return stats.RecordWithOptions(ctx, append(ros, stats.WithMeasurements(ms))...)
return stats.RecordWithOptions(ctx, append(ros, stats.WithMeasurements(mss...))...)
}
return mc.recorder(ctx, ms, ros...)
return mc.recorder(ctx, mss, ros...)
}
func createMetricsConfig(ops ExporterOptions, logger *zap.SugaredLogger) (*metricsConfig, error) {
@ -235,14 +235,24 @@ func createMetricsConfig(ops ExporterOptions, logger *zap.SugaredLogger) (*metri
if !allowCustomMetrics {
servingOrEventing := metricskey.KnativeRevisionMetrics.Union(
metricskey.KnativeTriggerMetrics).Union(metricskey.KnativeBrokerMetrics)
mc.recorder = func(ctx context.Context, ms stats.Measurement, ros ...stats.Options) error {
metricType := path.Join(mc.stackdriverMetricTypePrefix, ms.Measure().Name())
if servingOrEventing.Has(metricType) {
return stats.RecordWithOptions(ctx, append(ros, stats.WithMeasurements(ms))...)
mc.recorder = func(ctx context.Context, mss []stats.Measurement, ros ...stats.Options) error {
// Perform array filtering in place using two indices: w(rite)Index and r(ead)Index.
wIdx := 0
for rIdx := 0; rIdx < len(mss); rIdx++ {
metricType := path.Join(mc.stackdriverMetricTypePrefix, mss[rIdx].Measure().Name())
if servingOrEventing.Has(metricType) {
mss[wIdx] = mss[rIdx]
wIdx++
}
// Otherwise, skip the measurement (because it won't be accepted).
}
// Otherwise, skip (because it won't be accepted)
return nil
// Found no matched metrics.
if wIdx == 0 {
return nil
}
// Trim the list to the number of written objects.
mss = mss[:wIdx]
return stats.RecordWithOptions(ctx, append(ros, stats.WithMeasurements(mss...))...)
}
}
}

View File

@ -27,9 +27,12 @@ import (
// Record stores the given Measurement from `ms` in the current metrics backend.
func Record(ctx context.Context, ms stats.Measurement, ros ...stats.Options) {
mc := getCurMetricsConfig()
getCurMetricsConfig().record(ctx, []stats.Measurement{ms}, ros...)
}
mc.Record(ctx, ms, ros...)
// RecordBatch stores the given Measurements from `mss` in the current metrics backend.
func RecordBatch(ctx context.Context, mss ...stats.Measurement) {
getCurMetricsConfig().record(ctx, mss)
}
// Buckets125 generates an array of buckets with approximate powers-of-two

View File

@ -106,7 +106,7 @@ func (r *URIResolver) URIFromDestination(dest duckv1beta1.Destination, parent in
// URIFromDestinationV1 resolves a v1.Destination into a URL.
func (r *URIResolver) URIFromDestinationV1(dest duckv1.Destination, parent interface{}) (*apis.URL, error) {
if dest.Ref != nil {
url, err := r.URIFromObjectReference(dest.Ref, parent)
url, err := r.URIFromKnativeReference(dest.Ref, parent)
if err != nil {
return nil, err
}
@ -130,6 +130,10 @@ func (r *URIResolver) URIFromDestinationV1(dest duckv1.Destination, parent inter
return nil, errors.New("destination missing Ref and URI, expected at least one")
}
func (r *URIResolver) URIFromKnativeReference(ref *duckv1.KnativeReference, parent interface{}) (*apis.URL, error) {
return r.URIFromObjectReference(&corev1.ObjectReference{Name: ref.Name, Namespace: ref.Namespace, APIVersion: ref.APIVersion, Kind: ref.Kind}, parent)
}
// URIFromObjectReference resolves an ObjectReference to a URI string.
func (r *URIResolver) URIFromObjectReference(ref *corev1.ObjectReference, parent interface{}) (*apis.URL, error) {
if ref == nil {