This starts to sketch common libraries for instantiating informers/listers for a particular GroupVersionResource as one of our duck types.
You can instantiate a duck.InformerFactory like so:
```go
dynaClient, err := dynamic.NewForConfig(cfg)
if err != nil {
logger.Fatalf("Error building dynamic clientset: %v", err)
}
// Cache as the outermost layer so we only register the EventHandler once.
dif := &duck.CachedInformerFactory{
Delegate: &duck.EnqueueInformerFactory{
Delegate: &duck.TypedInformerFactory{
Client: dynaClient,
Type: &duckv1alpha1.Target{},
ResyncPeriod: 30 * time.Second,
StopChannel: stopCh,
},
EventHandler: cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
// Enqueue, obj is: *duckerv1alpha1.Target
},
UpdateFunc: func(old, new interface{}) {
// Enqueue, old and new are: *duckerv1alpha1.Target
},
},
},
}
```
Then, as you come across new GroupVersionResources that you want to handle:
```go
informer, lister, err := dif.Get(gvr)
if err != nil {
logger.Fatalf("Error starting shared index informer: %v", err)
}
```
With the `duck.TypedInformerFactory` the objects will be returned as the provided `Type:`, so in this example, you could safely write:
```go
elt, err := lister.ByNamespace(ns).Get(name)
if err != nil { ... }
target := elt.(*duckv1alpha1.Target)
// Stuff involving target.
```
The rate limiting queue makes the sleep necessary. Locally I see 0-2 failures when this is run with -count=10000. This bumps the sleep slightly to reduce this further.
Fixes: https://github.com/knative/pkg/issues/56
* first cut of defining Subscribable and Channelable
* address pr feedback
* remove now unnecessary From*Unstructured conversions
* address pr comments, add util_test
* Introduce LegacyTarget and make Target more structured
* add extra level of structure in Sinkable
* move util* to duck/util, change Sinkable string to SinkableDomain as per pr comments
* add callableDomain
* oops
* address PR feedback
* clarify comments
* Move util to pkg/duck
* Normalize the names of Status structs.
* Testing an idea for field errors.
* wrap other tests for webhook.
* move FieldError to Error, FieldErrors to FieldError
* Rename files to reflect their type.
* Reworked this to require no changes externally.
* test also.
* gotta cover those tests.
* nil check
* Adding Also.
* Clean up comments.
* Don't delete the tests.
* Null check test the clear.
* Fix nits.
* FieldError is now non-mutating.
* More errorf formatting fixes.
* I can make this even simpiler
* I can make this even MORE simpiler
* Add comment to make flow of also clear.
* fix comment, optimize make errors
* Prune the GenericCRD spec to what is used.
Encapsulate our change detection slightly.
* Support common spec mutations via duck typing.
This adds support for performing common mutations to objects via duck types and JSON patching.
Fixes: https://github.com/knative/pkg/issues/76
* Eliminate getSpecJSON thru schemaless duck typing.
This leverages a one-off trick to get the JSON of the spec field from arbitrary types.
* Adding common condition status.
* Saw another test that could be useful to have. added.
* ran hack/update-codegen.sh
* added ConditionSucceeded.
* moving the interface to just wrap the Condition[] object.
* checkpoint.
* Starting to reintegrate the work done in serving.
* Fixed up the unit tests.
* improve the test coverage on MarkTrue
* Moving conditionals to duck api.
* Adding more tests.
* Adding get/set tests.
* Some final nits for this ducking class.
* Adding .ViaIndex(1). to make spec.param[1] easier to do.
* Adding ViaKey
* fix order of bag example.
* Add code coverage to missed line.
* Adding ViaFieldIndex helper
* cleaning up.
* compress more.
* more cleanup
* test name
* Introduce an OwnerRefable interface
An OwnerRefable type provides sufficient information that we can
construct a metav1.OwnerReference from it, e.g. for
kmeta.NewOwnerReference, which does just that.
* Move interface to kmeta
This bootstraps this package with a useful collection of label methods for managing sub-resources. I'd initially written this as a way of managing versioned DaemonSet resources as part of WarmImage ([see here](62cad8045a/pkg/reconciler/warmimage/resources/meta.go (L28))).
I am upstreaming this here because I want to take advantage of it in Build for managing Image cache subresources of [Cluster]BuildTemplate resources.
* Few changes to the configmap package
- New* methods return concrete types
- defaultImpl is now InformedWatcher
- fixedImpl is now StaticWatcher
- Included a new ManualWatcher that mimics the InformedWatcher
in behaviour. ie. allows updates - making this a true 'mock'
* Include note about embedding the ManualWatcher in the InformedWatcher
* Update static_watcher.go
Fix some godoc
* shared scripts from test-infra live in //vendor/github.com/knative/test-infra/scripts;
* update `update-deps.sh` to keep only the scripts folder;
* all bash scripts were updated to use the vendored scripts;
Part of knative/test-infra#30.
This adds a logkey.Key for attaching the key being reconciled to a logger we embed into the context passed to Reconcile. The point of this is to enable us to eliminate [this](928d580756/pkg/reconciler/v1alpha1/service/service.go (L101-L104)) boilerplate from each of the Reconcilers.
These aren't identical, this has the form:
knative.dev/key: foo/bar
What it's replacing has the form:
knative.dev/namespace: foo
serving.knative.dev/service: bar
However, the type information present in the latter is redundant with the controller type that [should already be embedded](928d580756/pkg/reconciler/reconciler.go (L80)) in the logger.
In order to have a single webhook support multiple domain contexts, this reworks the `Handlers` argument to embed the `schema.GroupVersion` by wrapping the existing keys with it as a `schema.GroupVersionKind`.
This is mostly straightforward, but one oddity is that I discovered that `AdmissionRequest` gets this same tuple as the less capable `metav1.GroupVersionKind`, so there's a silly conversion we have to do.
I tried this manually vendored in serving with KPA and things worked great.
* Add Istio client from knative/serving
- Add Istio types in 'apis/istio/v1alpha3'
- Update codegen scripts
- Generate client in 'client'
- Add @tcnghia as owner for 'apis/istio'
Fixes#1
* nix linguring serving package dep
* cleanup vendor cache
* Mark /client as generated
* Fix verify-codegen script
* Run verify-codegen.sh via presubmit-tests.sh
* Remove Gatewaies -> Gateway hack
Looks like we don't need it anymore
The `controller.go` is from: https://github.com/knative/serving/pull/1770, however, this adds 100% coverage of `controller.go`, which we have been missing in `knative/serving`.
This also adds a `context.Context` to the `Reconcile` signature, to enable better sharing of logger setup across controllers.
Fixes: https://github.com/knative/pkg/issues/8