mirror of https://github.com/knative/caching.git
Auto-update dependencies (#191)
Produced via: `dep ensure -update knative.dev/test-infra knative.dev/pkg` /assign n3wscott /cc n3wscott
This commit is contained in:
parent
bb5b5155f3
commit
80ba6bd58f
|
@ -966,7 +966,7 @@
|
|||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:3d714b9e9535b4c878a16fff8c2ba5195df8c94d554a1bcff2e9f804350f4a5a"
|
||||
digest = "1:5acceb9ddfc654a91e633bb00531fc719fcaedda25d621162385ba5c2badc849"
|
||||
name = "knative.dev/pkg"
|
||||
packages = [
|
||||
"apis",
|
||||
|
@ -985,18 +985,18 @@
|
|||
"metrics/metricskey",
|
||||
]
|
||||
pruneopts = "T"
|
||||
revision = "b51ee347cbd2c26c1af45177d427ffb62b008b39"
|
||||
revision = "2fbb9db15cbb7971ad2b1f4266a437f5dcc33a51"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:4ba0f80b3feed917d2c9a1aa79ea95836c3aef84589431cff77ffd01615a1150"
|
||||
digest = "1:f0fb577e7a666886e560755c78e19b56b23303575677a9beca899316eb6a137c"
|
||||
name = "knative.dev/test-infra"
|
||||
packages = [
|
||||
"scripts",
|
||||
"tools/dep-collector",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "b0c4c4e1691282f24ccb3b5b0399952bf086edfc"
|
||||
revision = "5779f9c9458d0a85f734c0cad43c1510aa00b498"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:8730e0150dfb2b7e173890c8b9868e7a273082ef8e39f4940e3506a481cf895c"
|
||||
|
|
|
@ -101,6 +101,14 @@
|
|||
revision = "4b2b341e8d7715fae06375aa633dbb6e91b3fb46"
|
||||
version = "v1.0.0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:45c41cd27a8d986998680bfc86da0bbff5fa4f90d0f446c00636c8b099028ffe"
|
||||
name = "github.com/blang/semver"
|
||||
packages = ["."]
|
||||
pruneopts = "NUT"
|
||||
revision = "ba2c2ddd89069b46a7011d4106f6868f17ee1705"
|
||||
version = "v3.6.1"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:fdb4ed936abeecb46a8c27dcac83f75c05c87a46d9ec7711411eb785c213fa02"
|
||||
name = "github.com/census-instrumentation/opencensus-proto"
|
||||
|
@ -226,12 +234,12 @@
|
|||
version = "v1.0.0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:52c5834e2bebac9030c97cc0798ac11c3aa8a39f098aeb419f142533da6cd3cc"
|
||||
digest = "1:3ec6c8e4b700377066dbb5ab3155c55f97109ab6147fee9423a68506d79bbafa"
|
||||
name = "github.com/google/gofuzz"
|
||||
packages = ["."]
|
||||
pruneopts = "NUT"
|
||||
revision = "f140a6486e521aad38f5917de355cbf147cc0496"
|
||||
version = "v1.0.0"
|
||||
revision = "db92cf7ae75e4a7a28abc005addab2b394362888"
|
||||
version = "v1.1.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
|
@ -956,14 +964,18 @@
|
|||
version = "kubernetes-1.16.4"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:e00f750d45d512f0e7bf9c2c566e3cb13233b0c035a2b89d8c096dfc98e2e1c7"
|
||||
digest = "1:1aaf879947e3abf264929bb0220acced357f85da5ac0f58b10f0f8a5719a41ef"
|
||||
name = "k8s.io/apimachinery"
|
||||
packages = [
|
||||
"pkg/api/apitesting",
|
||||
"pkg/api/apitesting/fuzzer",
|
||||
"pkg/api/apitesting/roundtrip",
|
||||
"pkg/api/equality",
|
||||
"pkg/api/errors",
|
||||
"pkg/api/meta",
|
||||
"pkg/api/resource",
|
||||
"pkg/api/validation",
|
||||
"pkg/apis/meta/fuzzer",
|
||||
"pkg/apis/meta/internalversion",
|
||||
"pkg/apis/meta/v1",
|
||||
"pkg/apis/meta/v1/unstructured",
|
||||
|
@ -1339,6 +1351,7 @@
|
|||
"contrib.go.opencensus.io/exporter/stackdriver",
|
||||
"contrib.go.opencensus.io/exporter/stackdriver/monitoredresource",
|
||||
"contrib.go.opencensus.io/exporter/zipkin",
|
||||
"github.com/blang/semver",
|
||||
"github.com/davecgh/go-spew/spew",
|
||||
"github.com/evanphx/json-patch",
|
||||
"github.com/ghodss/yaml",
|
||||
|
@ -1349,6 +1362,7 @@
|
|||
"github.com/google/go-cmp/cmp",
|
||||
"github.com/google/go-cmp/cmp/cmpopts",
|
||||
"github.com/google/go-github/github",
|
||||
"github.com/google/gofuzz",
|
||||
"github.com/google/mako/clients/proto/analyzers/threshold_analyzer_go_proto",
|
||||
"github.com/google/mako/go/quickstore",
|
||||
"github.com/google/mako/proto/quickstore/quickstore_go_proto",
|
||||
|
@ -1366,7 +1380,6 @@
|
|||
"github.com/prometheus/client_golang/api",
|
||||
"github.com/prometheus/client_golang/api/prometheus/v1",
|
||||
"github.com/prometheus/common/model",
|
||||
"github.com/rogpeppe/go-internal/semver",
|
||||
"github.com/spf13/pflag",
|
||||
"github.com/tsenart/vegeta/lib",
|
||||
"go.opencensus.io/metric/metricdata",
|
||||
|
@ -1403,11 +1416,14 @@
|
|||
"k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/fake",
|
||||
"k8s.io/apiextensions-apiserver/pkg/client/informers/externalversions",
|
||||
"k8s.io/apiextensions-apiserver/pkg/client/informers/externalversions/apiextensions/v1beta1",
|
||||
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer",
|
||||
"k8s.io/apimachinery/pkg/api/apitesting/roundtrip",
|
||||
"k8s.io/apimachinery/pkg/api/equality",
|
||||
"k8s.io/apimachinery/pkg/api/errors",
|
||||
"k8s.io/apimachinery/pkg/api/meta",
|
||||
"k8s.io/apimachinery/pkg/api/resource",
|
||||
"k8s.io/apimachinery/pkg/api/validation",
|
||||
"k8s.io/apimachinery/pkg/apis/meta/fuzzer",
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1",
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured",
|
||||
"k8s.io/apimachinery/pkg/labels",
|
||||
|
@ -1423,6 +1439,7 @@
|
|||
"k8s.io/apimachinery/pkg/util/wait",
|
||||
"k8s.io/apimachinery/pkg/version",
|
||||
"k8s.io/apimachinery/pkg/watch",
|
||||
"k8s.io/client-go/discovery",
|
||||
"k8s.io/client-go/dynamic",
|
||||
"k8s.io/client-go/dynamic/fake",
|
||||
"k8s.io/client-go/informers",
|
||||
|
|
|
@ -15,6 +15,13 @@ required = [
|
|||
"github.com/gogo/protobuf/proto",
|
||||
]
|
||||
|
||||
[[constraint]]
|
||||
# We can drop this constraint when we switch to a
|
||||
# k8s version that merges this bump
|
||||
# https://github.com/kubernetes/kubernetes/pull/87431
|
||||
name = "github.com/google/gofuzz"
|
||||
version = "v1.1.0"
|
||||
|
||||
[[constraint]]
|
||||
name = "k8s.io/api"
|
||||
version = "kubernetes-1.16.4"
|
||||
|
|
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
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 fuzzer
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"net/url"
|
||||
|
||||
fuzz "github.com/google/gofuzz"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
|
||||
"k8s.io/apimachinery/pkg/runtime/serializer"
|
||||
"knative.dev/pkg/apis"
|
||||
)
|
||||
|
||||
// Funcs includes fuzzing funcs for knative.dev/serving types
|
||||
//
|
||||
// For other examples see
|
||||
// https://github.com/kubernetes/apimachinery/blob/master/pkg/apis/meta/fuzzer/fuzzer.go
|
||||
var Funcs = fuzzer.MergeFuzzerFuncs(
|
||||
func(codecs serializer.CodecFactory) []interface{} {
|
||||
return []interface{}{
|
||||
func(u *apis.URL, c fuzz.Continue) {
|
||||
u.Scheme = randStringAtoZ(c.Rand)
|
||||
u.Host = randStringAtoZ(c.Rand)
|
||||
u.User = url.UserPassword(
|
||||
randStringAtoZ(c.Rand), // username
|
||||
randStringAtoZ(c.Rand), // password
|
||||
)
|
||||
u.RawPath = url.PathEscape(c.RandString())
|
||||
u.RawQuery = url.QueryEscape(c.RandString())
|
||||
},
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
// FuzzConditions fuzzes the values for the conditions. It doesn't add
|
||||
// any new condition types
|
||||
//
|
||||
// Consumers should initialize their conditions prior to fuzzing them.
|
||||
// For example:
|
||||
//
|
||||
// func(s *SomeStatus, c fuzz.Continue) {
|
||||
// c.FuzzNoCustom(s) // fuzz the status object
|
||||
//
|
||||
// // Clear the random fuzzed condition
|
||||
// s.Status.SetConditions(nil)
|
||||
//
|
||||
// // Fuzz the known conditions except their type value
|
||||
// s.InitializeConditions()
|
||||
// fuzz.Conditions(&s.Status, c)
|
||||
// }
|
||||
func FuzzConditions(accessor apis.ConditionsAccessor, c fuzz.Continue) {
|
||||
conds := accessor.GetConditions()
|
||||
for i, cond := range conds {
|
||||
// Leave condition.Type untouched
|
||||
cond.Status = corev1.ConditionStatus(c.RandString())
|
||||
cond.Severity = apis.ConditionSeverity(c.RandString())
|
||||
cond.Message = c.RandString()
|
||||
cond.Reason = c.RandString()
|
||||
c.FuzzNoCustom(&cond.LastTransitionTime)
|
||||
conds[i] = cond
|
||||
}
|
||||
accessor.SetConditions(conds)
|
||||
}
|
||||
|
||||
// taken from gofuzz internals for RandString
|
||||
type charRange struct {
|
||||
first, last rune
|
||||
}
|
||||
|
||||
func (c *charRange) choose(r *rand.Rand) rune {
|
||||
count := int64(c.last - c.first + 1)
|
||||
ch := c.first + rune(r.Int63n(count))
|
||||
|
||||
return ch
|
||||
}
|
||||
|
||||
// not fully exhaustive
|
||||
func randStringAtoZ(r *rand.Rand) string {
|
||||
hostCharRange := charRange{'a', 'z'}
|
||||
|
||||
n := r.Intn(20)
|
||||
runes := make([]rune, n)
|
||||
for i := range runes {
|
||||
runes[i] = hostCharRange.choose(r)
|
||||
}
|
||||
return string(runes)
|
||||
}
|
|
@ -0,0 +1,256 @@
|
|||
/*
|
||||
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 roundtrip
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/rand"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/google/go-cmp/cmp/cmpopts"
|
||||
fuzz "github.com/google/gofuzz"
|
||||
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
|
||||
"k8s.io/apimachinery/pkg/api/apitesting/roundtrip"
|
||||
apiequality "k8s.io/apimachinery/pkg/api/equality"
|
||||
apimeta "k8s.io/apimachinery/pkg/api/meta"
|
||||
metafuzzer "k8s.io/apimachinery/pkg/apis/meta/fuzzer"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/runtime/serializer"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
"knative.dev/pkg/apis"
|
||||
)
|
||||
|
||||
type convertibleObject interface {
|
||||
runtime.Object
|
||||
apis.Convertible
|
||||
}
|
||||
|
||||
// globalNonRoundTrippableTypes are kinds that are effectively reserved
|
||||
// across all GroupVersions. They don't roundtrip
|
||||
//
|
||||
// This list comes from k8s.io/apimachinery. We can drop this constant when
|
||||
// the PR (https://github.com/kubernetes/kubernetes/pull/86959) merges and
|
||||
// we bump to a version that has the change
|
||||
var globalNonRoundTrippableTypes = sets.NewString(
|
||||
"ExportOptions",
|
||||
"GetOptions",
|
||||
// WatchEvent does not include kind and version and can only be deserialized
|
||||
// implicitly (if the caller expects the specific object). The watch call defines
|
||||
// the schema by content type, rather than via kind/version included in each
|
||||
// object.
|
||||
"WatchEvent",
|
||||
// ListOptions is now part of the meta group
|
||||
"ListOptions",
|
||||
// Delete options is only read in metav1
|
||||
"DeleteOptions",
|
||||
)
|
||||
|
||||
var (
|
||||
metaV1Types map[reflect.Type]struct{}
|
||||
metaV1ListType = reflect.TypeOf((*metav1.ListMetaAccessor)(nil)).Elem()
|
||||
)
|
||||
|
||||
func init() {
|
||||
gv := schema.GroupVersion{Group: "roundtrip.group", Version: "v1"}
|
||||
|
||||
scheme := runtime.NewScheme()
|
||||
|
||||
metav1.AddToGroupVersion(scheme, gv)
|
||||
metaV1Types = make(map[reflect.Type]struct{})
|
||||
|
||||
// Build up a list of types to ignore
|
||||
for _, t := range scheme.KnownTypes(gv) {
|
||||
metaV1Types[t] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
// ExternalTypesViaJSON applies the round-trip test to all external round-trippable Kinds
|
||||
// in the scheme. This is effectively testing the scenario:
|
||||
//
|
||||
// external -> json -> external
|
||||
//
|
||||
func ExternalTypesViaJSON(t *testing.T, scheme *runtime.Scheme, fuzzerFuncs fuzzer.FuzzerFuncs) {
|
||||
codecFactory := serializer.NewCodecFactory(scheme)
|
||||
|
||||
f := fuzzer.FuzzerFor(
|
||||
fuzzer.MergeFuzzerFuncs(metafuzzer.Funcs, fuzzerFuncs),
|
||||
rand.NewSource(rand.Int63()),
|
||||
codecFactory,
|
||||
)
|
||||
|
||||
f.SkipFieldsWithPattern(regexp.MustCompile("DeprecatedGeneration"))
|
||||
|
||||
kinds := scheme.AllKnownTypes()
|
||||
for gvk := range kinds {
|
||||
if gvk.Version == runtime.APIVersionInternal || globalNonRoundTrippableTypes.Has(gvk.Kind) {
|
||||
continue
|
||||
}
|
||||
t.Run(gvk.Group+"."+gvk.Version+"."+gvk.Kind, func(t *testing.T) {
|
||||
roundtrip.RoundTripSpecificKindWithoutProtobuf(t, gvk, scheme, codecFactory, f, nil)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// ExternalTypesViaHub applies the round-trip test to all external round-trippable Kinds
|
||||
// in the scheme. This is effectively testing the scenario:
|
||||
//
|
||||
// external version -> hub version -> external version
|
||||
//
|
||||
func ExternalTypesViaHub(t *testing.T, scheme, hubs *runtime.Scheme, fuzzerFuncs fuzzer.FuzzerFuncs) {
|
||||
f := fuzzer.FuzzerFor(
|
||||
fuzzer.MergeFuzzerFuncs(metafuzzer.Funcs, fuzzerFuncs),
|
||||
rand.NewSource(rand.Int63()),
|
||||
// This seems to be used for protobuf not json
|
||||
serializer.NewCodecFactory(scheme),
|
||||
)
|
||||
|
||||
f.SkipFieldsWithPattern(regexp.MustCompile("DeprecatedGeneration"))
|
||||
|
||||
for gvk, objType := range scheme.AllKnownTypes() {
|
||||
if gvk.Version == runtime.APIVersionInternal ||
|
||||
gvk.Group == "" || // K8s group
|
||||
globalNonRoundTrippableTypes.Has(gvk.Kind) {
|
||||
continue
|
||||
}
|
||||
|
||||
if _, ok := metaV1Types[objType]; ok {
|
||||
continue
|
||||
}
|
||||
|
||||
if reflect.PtrTo(objType).AssignableTo(metaV1ListType) {
|
||||
continue
|
||||
}
|
||||
|
||||
if hubs.Recognizes(gvk) {
|
||||
continue
|
||||
}
|
||||
|
||||
t.Run(gvk.Group+"."+gvk.Version+"."+gvk.Kind, func(t *testing.T) {
|
||||
for i := 0; i < *roundtrip.FuzzIters; i++ {
|
||||
roundTripViaHub(t, gvk, scheme, hubs, f)
|
||||
|
||||
if t.Failed() {
|
||||
break
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func roundTripViaHub(t *testing.T, gvk schema.GroupVersionKind, scheme, hubs *runtime.Scheme, f *fuzz.Fuzzer) {
|
||||
ctx := context.Background()
|
||||
|
||||
hub, hubGVK := hubInstanceForGK(t, hubs, gvk.GroupKind())
|
||||
obj := objForGVK(t, gvk, scheme)
|
||||
|
||||
fuzzObject(t, f, gvk, obj)
|
||||
|
||||
original := obj
|
||||
obj = obj.DeepCopyObject().(convertibleObject)
|
||||
|
||||
if !apiequality.Semantic.DeepEqual(original, obj) {
|
||||
t.Errorf("DeepCopy altered the object, diff: %v", diff(original, obj))
|
||||
return
|
||||
}
|
||||
|
||||
if err := hub.ConvertDown(ctx, obj); err != nil {
|
||||
t.Errorf("Conversion to hub (%s) failed: %s", hubGVK, err)
|
||||
}
|
||||
|
||||
if !apiequality.Semantic.DeepEqual(original, obj) {
|
||||
t.Errorf("Conversion to hub (%s) alterted the object, diff: %v", hubGVK, diff(original, obj))
|
||||
return
|
||||
}
|
||||
|
||||
newObj := objForGVK(t, gvk, scheme)
|
||||
if err := hub.ConvertUp(ctx, newObj); err != nil {
|
||||
t.Errorf("Conversion from hub (%s) failed: %s", hubGVK, err)
|
||||
t.Errorf("object: %#v", obj)
|
||||
return
|
||||
}
|
||||
|
||||
if !apiequality.Semantic.DeepEqual(obj, newObj) {
|
||||
t.Errorf("round trip through hub (%s) produced a diff: %s", hubGVK, diff(original, newObj))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func diff(obj1, obj2 interface{}) string {
|
||||
// knative.dev/pkg/apis.URL is an alias to net.URL which embeds a
|
||||
// url.Userinfo that has an unexported field
|
||||
return cmp.Diff(obj1, obj2, cmpopts.IgnoreUnexported(url.Userinfo{}))
|
||||
}
|
||||
|
||||
func objForGVK(t *testing.T,
|
||||
gvk schema.GroupVersionKind,
|
||||
scheme *runtime.Scheme,
|
||||
) convertibleObject {
|
||||
|
||||
t.Helper()
|
||||
|
||||
obj, err := scheme.New(gvk)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create object instance for type %s", err)
|
||||
}
|
||||
|
||||
objType, err := apimeta.TypeAccessor(obj)
|
||||
if err != nil {
|
||||
t.Fatalf("%q is not a TypeMeta and cannot be tested: %v", gvk, err)
|
||||
}
|
||||
objType.SetKind(gvk.Kind)
|
||||
objType.SetAPIVersion(gvk.GroupVersion().String())
|
||||
return obj.(convertibleObject)
|
||||
}
|
||||
|
||||
func fuzzObject(t *testing.T, fuzzer *fuzz.Fuzzer, gvk schema.GroupVersionKind, obj interface{}) {
|
||||
fuzzer.Fuzz(obj)
|
||||
|
||||
objType, err := apimeta.TypeAccessor(obj)
|
||||
if err != nil {
|
||||
t.Fatalf("%q is not a TypeMeta and cannot be tested: %v", gvk, err)
|
||||
}
|
||||
objType.SetKind(gvk.Kind)
|
||||
objType.SetAPIVersion(gvk.GroupVersion().String())
|
||||
}
|
||||
|
||||
func hubInstanceForGK(t *testing.T,
|
||||
hubs *runtime.Scheme,
|
||||
gk schema.GroupKind,
|
||||
) (apis.Convertible, schema.GroupVersionKind) {
|
||||
|
||||
t.Helper()
|
||||
|
||||
for hubGVK := range hubs.AllKnownTypes() {
|
||||
if hubGVK.GroupKind() == gk {
|
||||
obj, err := hubs.New(hubGVK)
|
||||
if err != nil {
|
||||
t.Fatalf("error creating objects %s", err)
|
||||
}
|
||||
|
||||
return obj.(apis.Convertible), hubGVK
|
||||
}
|
||||
}
|
||||
|
||||
t.Fatalf("hub type not found")
|
||||
return nil, schema.GroupVersionKind{}
|
||||
}
|
|
@ -19,19 +19,12 @@ package version
|
|||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/rogpeppe/go-internal/semver"
|
||||
"k8s.io/apimachinery/pkg/version"
|
||||
"github.com/blang/semver"
|
||||
"k8s.io/client-go/discovery"
|
||||
)
|
||||
|
||||
// ServerVersioner is an interface to mock the `ServerVersion`
|
||||
// method of the Kubernetes client's Discovery interface.
|
||||
// In an application `kubeClient.Discovery()` can be used to
|
||||
// suffice this interface.
|
||||
type ServerVersioner interface {
|
||||
ServerVersion() (*version.Info, error)
|
||||
}
|
||||
|
||||
const (
|
||||
// KubernetesMinVersionKey is the environment variable that can be used to override
|
||||
// the Kubernetes minimum version required by Knative.
|
||||
|
@ -53,20 +46,34 @@ func getMinimumVersion() string {
|
|||
//
|
||||
// A Kubernetes discovery client can be passed in as the versioner
|
||||
// like `CheckMinimumVersion(kubeClient.Discovery())`.
|
||||
func CheckMinimumVersion(versioner ServerVersioner) error {
|
||||
func CheckMinimumVersion(versioner discovery.ServerVersionInterface) error {
|
||||
v, err := versioner.ServerVersion()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
currentVersion := semver.Canonical(v.String())
|
||||
|
||||
minimumVersion := getMinimumVersion()
|
||||
currentVersion, err := semver.Make(normalizeVersion(v.GitVersion))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
minimumVersion, err := semver.Make(normalizeVersion(getMinimumVersion()))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Compare returns 1 if the first version is greater than the
|
||||
// second version.
|
||||
if semver.Compare(minimumVersion, currentVersion) == 1 {
|
||||
if currentVersion.LT(minimumVersion) {
|
||||
return fmt.Errorf("kubernetes version %q is not compatible, need at least %q (this can be overridden with the env var %q)",
|
||||
currentVersion, minimumVersion, KubernetesMinVersionKey)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func normalizeVersion(v string) string {
|
||||
if strings.HasPrefix(v, "v") {
|
||||
// No need to account for unicode widths.
|
||||
return v[1:]
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
|
|
@ -597,14 +597,19 @@ function get_canonical_path() {
|
|||
echo "$(cd ${path%/*} && echo $PWD/${path##*/})"
|
||||
}
|
||||
|
||||
# Returns whether the current branch is a release branch.
|
||||
function is_release_branch() {
|
||||
# Returns the current branch.
|
||||
function current_branch() {
|
||||
local branch_name=""
|
||||
# Get the branch name from Prow's env var, see https://github.com/kubernetes/test-infra/blob/master/prow/jobs.md.
|
||||
# Otherwise, try getting the current branch from git.
|
||||
(( IS_PROW )) && branch_name="${PULL_BASE_REF:-}"
|
||||
[[ -z "${branch_name}" ]] && branch_name="$(git rev-parse --abbrev-ref HEAD)"
|
||||
[[ ${branch_name} =~ ^release-[0-9\.]+$ ]]
|
||||
echo "${branch_name}"
|
||||
}
|
||||
|
||||
# Returns whether the current branch is a release branch.
|
||||
function is_release_branch() {
|
||||
[[ $(current_branch) =~ ^release-[0-9\.]+$ ]]
|
||||
}
|
||||
|
||||
# Returns the URL to the latest manifest for the given Knative project.
|
||||
|
@ -615,19 +620,23 @@ function get_latest_knative_yaml_source() {
|
|||
local yaml_name="$2"
|
||||
# If it's a release branch, the yaml source URL should point to a specific version.
|
||||
if is_release_branch; then
|
||||
# Get the latest tag name for the current branch, which is likely formatted as v0.5.0
|
||||
local tag_name="$(git describe --tags --abbrev=0)"
|
||||
# The given repo might not have this tag, so we need to find its latest release manifest with the same major&minor version.
|
||||
local major_minor="$(echo ${tag_name} | cut -d. -f1-2)"
|
||||
local yaml_source_path="$(gsutil ls gs://knative-releases/${repo_name}/previous/${major_minor}.*/${yaml_name}.yaml \
|
||||
# Extract the release major&minor version from the branch name.
|
||||
local branch_name="$(current_branch)"
|
||||
local major_minor="${branch_name##release-}"
|
||||
# Find the latest release manifest with the same major&minor version.
|
||||
local yaml_source_path="$(
|
||||
gsutil ls gs://knative-releases/${repo_name}/previous/v${major_minor}.*/${yaml_name}.yaml 2> /dev/null \
|
||||
| sort \
|
||||
| tail -n 1 \
|
||||
| cut -b6-)"
|
||||
echo "https://storage.googleapis.com/${yaml_source_path}"
|
||||
# If it's not a release branch, the yaml source URL should be nightly build.
|
||||
else
|
||||
echo "https://storage.googleapis.com/knative-nightly/${repo_name}/latest/${yaml_name}.yaml"
|
||||
# The version does exist, return it.
|
||||
if [[ -n "${yaml_source_path}" ]]; then
|
||||
echo "https://storage.googleapis.com/${yaml_source_path}"
|
||||
return
|
||||
fi
|
||||
# Otherwise, fall back to nightly.
|
||||
fi
|
||||
echo "https://storage.googleapis.com/knative-nightly/${repo_name}/latest/${yaml_name}.yaml"
|
||||
}
|
||||
|
||||
# Initializations that depend on previous functions.
|
||||
|
|
Loading…
Reference in New Issue