[master] Auto-update dependencies (#254)

Produced via:
  `./hack/update-deps.sh --upgrade && ./hack/update-codegen.sh`
/assign n3wscott vagababov
/cc n3wscott vagababov
This commit is contained in:
Matt Moore 2020-04-22 08:41:41 -07:00 committed by GitHub
parent aaaa1a555a
commit ac178bf243
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 65 additions and 6 deletions

6
Gopkg.lock generated
View File

@ -966,7 +966,7 @@
[[projects]] [[projects]]
branch = "master" branch = "master"
digest = "1:518e5e7cb6aa149f3ea33bbfdfd367e4ab413d3405e33d85e09ac1f9b7a74c1f" digest = "1:e22353ddf843dd7a2114cd6384fdd84b7200d2fbb86aa864af91d60110954e3f"
name = "knative.dev/pkg" name = "knative.dev/pkg"
packages = [ packages = [
"apis", "apis",
@ -986,7 +986,7 @@
"reconciler", "reconciler",
] ]
pruneopts = "T" pruneopts = "T"
revision = "9320e44d1bf75c228b98b30cedcb98bb6e1424ee" revision = "8aa4090a02769edfd8494007c50424cc87c6a655"
[[projects]] [[projects]]
branch = "master" branch = "master"
@ -997,7 +997,7 @@
"tools/dep-collector", "tools/dep-collector",
] ]
pruneopts = "UT" pruneopts = "UT"
revision = "891d25bbf859bfc829b515068cc3e167a7fcc528" revision = "349504bd2094689586c7399ceb1af96fcbad1026"
[[projects]] [[projects]]
digest = "1:8730e0150dfb2b7e173890c8b9868e7a273082ef8e39f4940e3506a481cf895c" digest = "1:8730e0150dfb2b7e173890c8b9868e7a273082ef8e39f4940e3506a481cf895c"

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

@ -1369,14 +1369,14 @@
[[projects]] [[projects]]
branch = "master" branch = "master"
digest = "1:dc73d65f40ea05b1d0db96ae5491b6ebc162bb59b3ac5a252cdf87848bc7a4b7" digest = "1:8a965ebe2d83033f6a07e926357f7341b6c7f42e165a3e13c7c8113b953a265b"
name = "knative.dev/test-infra" name = "knative.dev/test-infra"
packages = [ packages = [
"scripts", "scripts",
"tools/dep-collector", "tools/dep-collector",
] ]
pruneopts = "UT" pruneopts = "UT"
revision = "74b24ca44778c3a69ecc193250cdddb5d0e64b88" revision = "891d25bbf859bfc829b515068cc3e167a7fcc528"
[[projects]] [[projects]]
digest = "1:8730e0150dfb2b7e173890c8b9868e7a273082ef8e39f4940e3506a481cf895c" digest = "1:8730e0150dfb2b7e173890c8b9868e7a273082ef8e39f4940e3506a481cf895c"

View File

@ -474,6 +474,7 @@ func RunLeaderElected(ctx context.Context, logger *zap.SugaredLogger, run func(c
logger.Fatal("leaderelection lost") logger.Fatal("leaderelection lost")
}, },
}, },
ReleaseOnCancel: true,
// TODO: use health check watchdog, knative/pkg#1048 // TODO: use health check watchdog, knative/pkg#1048
Name: component, Name: component,
}) })

View File

@ -321,7 +321,9 @@ func (r *TableRow) Test(t *testing.T, factory Factory) {
if got.GetName() != want.GetName() { if got.GetName() != want.GetName() {
t.Errorf("Unexpected patch[%d]: %#v", i, got) t.Errorf("Unexpected patch[%d]: %#v", i, got)
} }
if !r.SkipNamespaceValidation && got.GetNamespace() != expectedNamespace { if (!r.SkipNamespaceValidation && got.GetNamespace() != expectedNamespace) &&
(!r.SkipNamespaceValidation && got.GetResource().GroupResource().Resource != "namespaces" &&
got.GetName() != expectedNamespace) {
t.Errorf("Unexpected patch[%d]: %#v", i, got) t.Errorf("Unexpected patch[%d]: %#v", i, got)
} }
if diff := cmp.Diff(string(want.GetPatch()), string(got.GetPatch())); diff != "" { if diff := cmp.Diff(string(want.GetPatch()), string(got.GetPatch())); diff != "" {

View File

@ -32,6 +32,7 @@ import (
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/dynamic" "k8s.io/client-go/dynamic"
corev1listers "k8s.io/client-go/listers/core/v1"
"k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/record" "k8s.io/client-go/tools/record"
"knative.dev/pkg/apis" "knative.dev/pkg/apis"
@ -43,6 +44,12 @@ import (
"knative.dev/pkg/tracker" "knative.dev/pkg/tracker"
) )
var jsonLabelPatch = map[string]interface{}{
"metadata": map[string]interface{}{
"labels": map[string]string{duck.BindingIncludeLabel: "true"},
},
}
// BaseReconciler helps implement controller.Reconciler for Binding resources. // BaseReconciler helps implement controller.Reconciler for Binding resources.
type BaseReconciler struct { type BaseReconciler struct {
// The GVR of the "primary key" resource for this reconciler. // The GVR of the "primary key" resource for this reconciler.
@ -75,6 +82,9 @@ type BaseReconciler struct {
// Recorder is an event recorder for recording Event resources to the // Recorder is an event recorder for recording Event resources to the
// Kubernetes API. // Kubernetes API.
Recorder record.EventRecorder Recorder record.EventRecorder
// Namespace Lister
NamespaceLister corev1listers.NamespaceLister
} }
// Check that our Reconciler implements controller.Reconciler // Check that our Reconciler implements controller.Reconciler
@ -229,6 +239,44 @@ func (r *BaseReconciler) RemoveFinalizer(ctx context.Context, fb kmeta.Accessor)
return err return err
} }
func (r *BaseReconciler) labelNamespace(ctx context.Context, subject tracker.Reference) error {
namespaceObject, err := r.NamespaceLister.Get(subject.Namespace)
if apierrs.IsNotFound(err) {
logging.FromContext(ctx).Infof("Error getting namespace (not found): %v", err)
return err
} else if err != nil {
logging.FromContext(ctx).Infof("Error getting namespace: %v", err)
return err
}
labels := namespaceObject.GetLabels()
if labels[duck.BindingIncludeLabel] != "" || labels[duck.BindingExcludeLabel] != "" {
return nil
}
patch, err := json.Marshal(jsonLabelPatch)
if err != nil {
logging.FromContext(ctx).Infof("Error generating json patch: %v, to namespace: %s", err, subject.Namespace)
return nil
}
// Determine the GroupVersionResource of the subject reference
gvr := schema.GroupVersionResource{
Group: "",
Version: "v1",
Resource: "namespaces",
}
_, err = r.DynamicClient.Resource(gvr).Patch(subject.Namespace, types.MergePatchType, patch, metav1.PatchOptions{})
if err != nil {
logging.FromContext(ctx).Infof("Error applying patch to namespace: %s: %v", subject.Namespace, err)
return err
}
return nil
}
// ReconcileSubject handles applying the provided Binding "mutation" (Do or // ReconcileSubject handles applying the provided Binding "mutation" (Do or
// Undo) to the Binding's subject(s). // Undo) to the Binding's subject(s).
func (r *BaseReconciler) ReconcileSubject(ctx context.Context, fb Bindable, mutation Mutation) error { func (r *BaseReconciler) ReconcileSubject(ctx context.Context, fb Bindable, mutation Mutation) error {
@ -269,6 +317,10 @@ func (r *BaseReconciler) ReconcileSubject(ctx context.Context, fb Bindable, muta
} else if err != nil { } else if err != nil {
return fmt.Errorf("error fetching Pod Speccable %v: %v", subject, err) return fmt.Errorf("error fetching Pod Speccable %v: %v", subject, err)
} }
err = r.labelNamespace(ctx, subject)
if err != nil {
return err
}
referents = append(referents, psObj.(*duckv1.WithPod)) referents = append(referents, psObj.(*duckv1.WithPod))
} else { } else {
// Otherwise, the subject is referenced by selector, so compile // Otherwise, the subject is referenced by selector, so compile
@ -281,6 +333,10 @@ func (r *BaseReconciler) ReconcileSubject(ctx context.Context, fb Bindable, muta
if err != nil { if err != nil {
return fmt.Errorf("error fetching Pod Speccable %v: %v", subject, err) return fmt.Errorf("error fetching Pod Speccable %v: %v", subject, err)
} }
err = r.labelNamespace(ctx, subject)
if err != nil {
return err
}
// Type cast the returned resources into our referent list. // Type cast the returned resources into our referent list.
for _, psObj := range psObjs { for _, psObj := range psObjs {
referents = append(referents, psObj.(*duckv1.WithPod)) referents = append(referents, psObj.(*duckv1.WithPod))