mirror of https://github.com/knative/caching.git
[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:
parent
aaaa1a555a
commit
ac178bf243
|
@ -966,7 +966,7 @@
|
|||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:518e5e7cb6aa149f3ea33bbfdfd367e4ab413d3405e33d85e09ac1f9b7a74c1f"
|
||||
digest = "1:e22353ddf843dd7a2114cd6384fdd84b7200d2fbb86aa864af91d60110954e3f"
|
||||
name = "knative.dev/pkg"
|
||||
packages = [
|
||||
"apis",
|
||||
|
@ -986,7 +986,7 @@
|
|||
"reconciler",
|
||||
]
|
||||
pruneopts = "T"
|
||||
revision = "9320e44d1bf75c228b98b30cedcb98bb6e1424ee"
|
||||
revision = "8aa4090a02769edfd8494007c50424cc87c6a655"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
|
@ -997,7 +997,7 @@
|
|||
"tools/dep-collector",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "891d25bbf859bfc829b515068cc3e167a7fcc528"
|
||||
revision = "349504bd2094689586c7399ceb1af96fcbad1026"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:8730e0150dfb2b7e173890c8b9868e7a273082ef8e39f4940e3506a481cf895c"
|
||||
|
|
|
@ -1369,14 +1369,14 @@
|
|||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:dc73d65f40ea05b1d0db96ae5491b6ebc162bb59b3ac5a252cdf87848bc7a4b7"
|
||||
digest = "1:8a965ebe2d83033f6a07e926357f7341b6c7f42e165a3e13c7c8113b953a265b"
|
||||
name = "knative.dev/test-infra"
|
||||
packages = [
|
||||
"scripts",
|
||||
"tools/dep-collector",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "74b24ca44778c3a69ecc193250cdddb5d0e64b88"
|
||||
revision = "891d25bbf859bfc829b515068cc3e167a7fcc528"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:8730e0150dfb2b7e173890c8b9868e7a273082ef8e39f4940e3506a481cf895c"
|
||||
|
|
|
@ -474,6 +474,7 @@ func RunLeaderElected(ctx context.Context, logger *zap.SugaredLogger, run func(c
|
|||
logger.Fatal("leaderelection lost")
|
||||
},
|
||||
},
|
||||
ReleaseOnCancel: true,
|
||||
// TODO: use health check watchdog, knative/pkg#1048
|
||||
Name: component,
|
||||
})
|
||||
|
|
|
@ -321,7 +321,9 @@ func (r *TableRow) Test(t *testing.T, factory Factory) {
|
|||
if got.GetName() != want.GetName() {
|
||||
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)
|
||||
}
|
||||
if diff := cmp.Diff(string(want.GetPatch()), string(got.GetPatch())); diff != "" {
|
||||
|
|
|
@ -32,6 +32,7 @@ import (
|
|||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
"k8s.io/client-go/dynamic"
|
||||
corev1listers "k8s.io/client-go/listers/core/v1"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
"k8s.io/client-go/tools/record"
|
||||
"knative.dev/pkg/apis"
|
||||
|
@ -43,6 +44,12 @@ import (
|
|||
"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.
|
||||
type BaseReconciler struct {
|
||||
// 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
|
||||
// Kubernetes API.
|
||||
Recorder record.EventRecorder
|
||||
|
||||
// Namespace Lister
|
||||
NamespaceLister corev1listers.NamespaceLister
|
||||
}
|
||||
|
||||
// Check that our Reconciler implements controller.Reconciler
|
||||
|
@ -229,6 +239,44 @@ func (r *BaseReconciler) RemoveFinalizer(ctx context.Context, fb kmeta.Accessor)
|
|||
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
|
||||
// Undo) to the Binding's subject(s).
|
||||
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 {
|
||||
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))
|
||||
} else {
|
||||
// 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 {
|
||||
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.
|
||||
for _, psObj := range psObjs {
|
||||
referents = append(referents, psObj.(*duckv1.WithPod))
|
||||
|
|
Loading…
Reference in New Issue