Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bump k8s to v1.20.7 #2145

Merged
merged 14 commits into from
Jun 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 6 additions & 2 deletions apiextensions/storageversion/migrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ var (
func TestMigrate(t *testing.T) {
// setup
resources := []runtime.Object{fake("first"), fake("second")}
dclient := dynamicFake.NewSimpleDynamicClient(runtime.NewScheme(), resources...)
dclient := dynamicFake.NewSimpleDynamicClientWithCustomListKinds(runtime.NewScheme(), gvrToListKind, resources...)
cclient := apixFake.NewSimpleClientset(fakeCRD)
m := NewMigrator(dclient, cclient)

Expand Down Expand Up @@ -136,7 +136,7 @@ func TestMigrate_Errors(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
resources := []runtime.Object{fake("first"), fake("second")}
dclient := dynamicFake.NewSimpleDynamicClient(runtime.NewScheme(), resources...)
dclient := dynamicFake.NewSimpleDynamicClientWithCustomListKinds(runtime.NewScheme(), gvrToListKind, resources...)
cclient := apixFake.NewSimpleClientset(fakeCRD)

if test.crd != nil {
Expand Down Expand Up @@ -195,6 +195,10 @@ func getPatchActions(actions []k8stesting.Action) []k8stesting.PatchAction {
return patches
}

var gvrToListKind = map[schema.GroupVersionResource]string{
{Group: "group.dev", Version: "v1", Resource: "fakes"}: "SomeList",
}

func fake(name string) runtime.Object {
return &unstructured.Unstructured{
Object: map[string]interface{}{
Expand Down
6 changes: 5 additions & 1 deletion apis/duck/typed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ import (
. "knative.dev/pkg/testing"
)

var gvrToListKind = map[schema.GroupVersionResource]string{
{Group: "pkg.knative.dev", Version: "v2", Resource: "resources"}: "SomeList",
}

func TestSimpleList(t *testing.T) {
scheme := runtime.NewScheme()
AddToScheme(scheme)
Expand All @@ -46,7 +50,7 @@ func TestSimpleList(t *testing.T) {

// Despite the signature allowing `...runtime.Object`, this method
// will not work properly unless the passed objects are `unstructured.Unstructured`
client := fake.NewSimpleDynamicClient(scheme, &unstructured.Unstructured{
client := fake.NewSimpleDynamicClientWithCustomListKinds(scheme, gvrToListKind, &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "pkg.knative.dev/v2",
"kind": "Resource",
Expand Down
23 changes: 11 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ require (
github.com/davecgh/go-spew v1.1.1
github.com/dgryski/go-gk v0.0.0-20200319235926-a69029f61654 // indirect
github.com/evanphx/json-patch/v5 v5.5.0
github.com/go-openapi/spec v0.19.6 // indirect
github.com/go-openapi/swag v0.19.7 // indirect
github.com/go-logr/logr v0.4.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/swag v0.19.15 // indirect
github.com/gobuffalo/flect v0.2.2
github.com/golang/protobuf v1.5.2
github.com/google/go-cmp v0.5.6
Expand All @@ -32,9 +34,7 @@ require (
github.com/influxdata/tdigest v0.0.0-20181121200506-bf2b5ad3c0a9 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/kelseyhightower/envconfig v1.4.0
github.com/kr/text v0.2.0 // indirect
github.com/mailru/easyjson v0.7.1-0.20191009090205-6c0755d89d1e // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/onsi/gomega v1.10.1 // indirect
github.com/openzipkin/zipkin-go v0.2.5
github.com/prometheus/client_golang v1.11.0
Expand All @@ -56,14 +56,13 @@ require (
google.golang.org/genproto v0.0.0-20210416161957-9910b6c460de
google.golang.org/grpc v1.38.0
google.golang.org/protobuf v1.26.0
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
k8s.io/api v0.19.7
k8s.io/apiextensions-apiserver v0.19.7
k8s.io/apimachinery v0.19.7
k8s.io/client-go v0.19.7
k8s.io/code-generator v0.19.7
k8s.io/gengo v0.0.0-20200428234225-8167cfdcfc14
k8s.io/api v0.20.7
k8s.io/apiextensions-apiserver v0.20.7
k8s.io/apimachinery v0.20.7
k8s.io/client-go v0.20.7
k8s.io/code-generator v0.20.7
k8s.io/gengo v0.0.0-20210203185629-de9496dff47b
k8s.io/klog v1.0.0
knative.dev/hack v0.0.0-20210609124042-e35bcb8f21ec
sigs.k8s.io/yaml v1.2.0
Expand Down
200 changes: 75 additions & 125 deletions go.sum

Large diffs are not rendered by default.

42 changes: 40 additions & 2 deletions injection/clients/dynamicclient/fake/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,65 @@ package fake

import (
"context"
"strings"

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/dynamic/fake"
k8sscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"

"knative.dev/pkg/injection"
"knative.dev/pkg/injection/clients/dynamicclient"
"knative.dev/pkg/logging"
pkgunstructured "knative.dev/pkg/unstructured"
)

func init() {
injection.Fake.RegisterClient(withClient)
}

func withClient(ctx context.Context, cfg *rest.Config) context.Context {
ctx, _ = With(ctx, runtime.NewScheme())
scheme := runtime.NewScheme()
k8sscheme.AddToScheme(scheme)
ctx, _ = With(ctx, scheme)
return ctx
}

func With(ctx context.Context, scheme *runtime.Scheme, objects ...runtime.Object) (context.Context, *fake.FakeDynamicClient) {
cs := fake.NewSimpleDynamicClient(scheme, objects...)
// We create a scheme were we define all our types and lists
// and have them map to unstructured types
//
// This was a K8s 1.20 breaking change
unstructuredScheme := runtime.NewScheme()
for gvk := range scheme.AllKnownTypes() {
if unstructuredScheme.Recognizes(gvk) {
continue
}
if strings.HasSuffix(gvk.Kind, "List") {
unstructuredScheme.AddKnownTypeWithName(gvk, &unstructured.UnstructuredList{})
continue
}
unstructuredScheme.AddKnownTypeWithName(gvk, &unstructured.Unstructured{})
}

objects, err := pkgunstructured.ConvertManyToObjects(scheme, objects)
if err != nil {
panic(err)
}

for _, obj := range objects {
gvk := obj.GetObjectKind().GroupVersionKind()
if !unstructuredScheme.Recognizes(gvk) {
unstructuredScheme.AddKnownTypeWithName(gvk, &unstructured.Unstructured{})
}
gvk.Kind += "List"
if !unstructuredScheme.Recognizes(gvk) {
unstructuredScheme.AddKnownTypeWithName(gvk, &unstructured.UnstructuredList{})
}
}

cs := fake.NewSimpleDynamicClient(unstructuredScheme, objects...)
return context.WithValue(ctx, dynamicclient.Key{}, cs), cs
}

Expand Down
18 changes: 18 additions & 0 deletions resolver/addressable_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes/scheme"
"knative.dev/pkg/apis"
Expand Down Expand Up @@ -57,6 +58,23 @@ func init() {
// Add types to scheme
duckv1alpha1.AddToScheme(scheme.Scheme)
duckv1beta1.AddToScheme(scheme.Scheme)

scheme.Scheme.AddKnownTypeWithName(
schema.FromAPIVersionAndKind(unaddressableAPIVersion, unaddressableKind),
&unstructured.Unstructured{},
)
scheme.Scheme.AddKnownTypeWithName(
schema.FromAPIVersionAndKind(unaddressableAPIVersion, unaddressableKind+"List"),
&unstructured.UnstructuredList{},
)
scheme.Scheme.AddKnownTypeWithName(
schema.FromAPIVersionAndKind(addressableAPIVersion, addressableKind),
&unstructured.Unstructured{},
)
scheme.Scheme.AddKnownTypeWithName(
schema.FromAPIVersionAndKind(addressableAPIVersion, addressableKind+"List"),
&unstructured.UnstructuredList{},
)
}

func TestGetURIDestinationV1Beta1(t *testing.T) {
Expand Down
21 changes: 21 additions & 0 deletions third_party/VENDOR-LICENSE/github.com/josharian/intern/license.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Josh Bleecher Snyder

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
13 changes: 7 additions & 6 deletions tracker/interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"testing"

"github.com/google/go-cmp/cmp"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"knative.dev/pkg/apis"
Expand Down Expand Up @@ -95,7 +96,7 @@ func TestValidateObjectReference(t *testing.T) {
Name: "c.d",
},
want: &apis.FieldError{
Message: "invalid value: a DNS-1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name', or '123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?')",
Message: "invalid value: a lowercase RFC 1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name', or '123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?')",
Paths: []string{"namespace", "name"},
},
}, {
Expand All @@ -117,8 +118,8 @@ func TestValidateObjectReference(t *testing.T) {
t.Errorf("ValidateObjectReference() = %v, wanted %v", got, test.want)
} else if test.want != nil {
want, got := test.want.Error(), got.Error()
if got != want {
t.Errorf("ValidateObjectReference() = %s, wanted %s", got, want)
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("ValidateObjectReference() diff: %s", diff)
}
}
})
Expand Down Expand Up @@ -177,7 +178,7 @@ func TestValidate(t *testing.T) {
Name: "c.d",
},
want: &apis.FieldError{
Message: "invalid value: a DNS-1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name', or '123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?')",
Message: "invalid value: a lowercase RFC 1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name', or '123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?')",
Paths: []string{"namespace", "name"},
},
}, {
Expand Down Expand Up @@ -224,8 +225,8 @@ func TestValidate(t *testing.T) {
t.Errorf("ValidateObjectReference() = %v, wanted %v", got, test.want)
} else if test.want != nil {
want, got := test.want.Error(), got.Error()
if got != want {
t.Errorf("ValidateObjectReference() = %s, wanted %s", got, want)
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("ValidateObjectReference() diff %s", diff)
}
}
})
Expand Down
80 changes: 80 additions & 0 deletions unstructured/unstructured.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
Copyright 2021 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 unstructured

import (
"fmt"

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
)

// ConvertTo converts a runtime.Object to an unstructured.Unstructured type
func ConvertTo(s *runtime.Scheme, obj runtime.Object) (*unstructured.Unstructured, error) {
var (
err error
u unstructured.Unstructured
)

u.Object, err = runtime.DefaultUnstructuredConverter.ToUnstructured(obj)
if err != nil {
return nil, fmt.Errorf("failed to convert to unstructured: %w", err)
}

gvk := u.GroupVersionKind()
if gvk.Group == "" || gvk.Kind == "" {
gvks, _, err := s.ObjectKinds(obj)
if err != nil {
return nil, fmt.Errorf("failed to convert to unstructured: %w", err)
}
apiv, k := gvks[0].ToAPIVersionAndKind()
u.SetAPIVersion(apiv)
u.SetKind(k)
}
return &u, nil
}

// ConvertManyTo converts a slice of runtime.Object to a slice of *unstructured.Unstructured
func ConvertManyTo(s *runtime.Scheme, objs []runtime.Object) ([]*unstructured.Unstructured, error) {
ul := make([]*unstructured.Unstructured, 0, len(objs))

for _, obj := range objs {
u, err := ConvertTo(s, obj)
if err != nil {
return nil, err
}

ul = append(ul, u)
}
return ul, nil
}

// ConvertManyToObjects converts a slice of runtime.Object to a slice of runtime.Objects
// where each element is of the type *unstructured.Unstructured
func ConvertManyToObjects(s *runtime.Scheme, objs []runtime.Object) ([]runtime.Object, error) {
ul := make([]runtime.Object, 0, len(objs))

for _, obj := range objs {
u, err := ConvertTo(s, obj)
if err != nil {
return nil, err
}

ul = append(ul, u)
}
return ul, nil
}
2 changes: 2 additions & 0 deletions vendor/github.com/go-logr/logr/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading