Commit Graph

31 Commits

Author SHA1 Message Date
Matt Moore 46bd3d242b Add a test that shows modeling /scale as a duck. (#112)
There are a number of notable differences:
 * Selector is part of Spec not Status,
 * Selector is structured vs. `string`,
 * The Replicas in Spec is a pointer.
2018-10-04 09:48:24 -07:00
Matt Moore fd1e3cc5c9 Add logic to convert the watch.Interface. (#106)
The watch logic returns events containing `unstructured.Unstructured`.  This adds a proxy that converts those to the appropriate structured type.
2018-09-29 21:38:22 -07:00
Matt Moore bb5b93d475 Link to the doc on Duck Typing, which I missed adding before. (#105) 2018-09-28 16:33:22 -07:00
Scott Nichols 3155feb330 Can I has slash approve? (#100) 2018-09-27 15:32:22 -07:00
Vincent Demeester 781d6bbc47 Move the use of `VerifyType` in tests (#98)
* Change VerifyType to return an error instead of panicking

Signed-off-by: Vincent Demeester <vdemeest@redhat.com>

* Move the use of `VerifyType` in tests

Those calls to `duck.VerifyType` are done at runtime and thus could be
costly at program startup. Putting them under tests ensure we still
assert those types but during unit testing.

Signed-off-by: Vincent Demeester <vdemeest@redhat.com>
2018-09-27 15:16:22 -07:00
Dave Protasowski 2b6bdaba3b Use zaptest logger for our TestLogger (#89)
* Bump go.uber.org/zap to 67bc79

* Use the zaptest logger which uses testing.T.Log methods
2018-09-25 21:40:20 -07:00
Scott Nichols 07104dad53 Use legitimate methods to enable get and set conditions. (#80)
* Use reflection to get and set conditions.

* Update comment.

* limiting the object on the way in, no need to double check it is a struct.

* Reorder the class, and add a comment for getConditions

* Adding relection and duck type checking.

* Fix typos.
2018-09-25 13:35:21 -07:00
Matt Moore d77de96af3 Add an example / test that we can Duck type Core K8s resources. (#93)
This defines a simple test duck type called PodSpecable, which has the same shape for embedding a corev1.PodTemplateSpec as numerous core Kubernetes resource: ReplicaSet, Deployment, StatefulSet, DaemonSet, and Job.
2018-09-25 09:22:20 -07:00
Ivan Mikushin 9223894e3a Access Conditions on KResourceStatus (#92)
* Implement ConditionsAccessor interface on KResourceStatus

* Remove GetCondition(ConditionType), SetCondition(*Condition)
2018-09-25 08:34:20 -07:00
Matt Moore 3473880674 Informers / Listers for Duck Types. (#86)
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.
```
2018-09-24 20:10:20 -07:00
Scott Nichols 7aae4072d7 Sort keys and paths for FieldError. (#90) 2018-09-24 15:48:20 -07:00
Matt Moore e71b1a477d Create a helper for synthesizing patches. (#87) 2018-09-24 15:36:20 -07:00
Matt Moore f81d0f8f0f Define an interface for interacting with Listable objects. (#85)
This will help us build informers from the dynamic API client.
2018-09-21 14:34:19 -07:00
Matt Moore dd52fc8a4b Create a common way for turning GVK into GVR. (#84)
We've got a few of these evolving, and so I wanted to create a helper (in the hopes that someone will solve our pluralization properly).

[knative/eventing](https://github.com/knative/eventing/pull/437/files#diff-df3ef4686fadf4bf98714d6163f81654R277)
[knative/servingm](69811e7a91/pkg/reconciler/v1alpha1/autoscaling/kpa_scaler.go (L119))
2018-09-21 14:07:21 -07:00
Ville Aikas 51f6214fee Add Sinkable and Channelable types. Fix Subscribable types. (#79)
* 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.
2018-09-20 16:01:19 -07:00
Scott Nichols a133825579 Adding also always to return nil for nil errors (#83) 2018-09-20 15:00:19 -07:00
Scott Nichols 70762ec49b Reintroduce FieldError (#77)
* 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
2018-09-20 09:24:19 -07:00
Matt Moore c15d7c8f22 Eliminate custom methods from GenericCRD (#78)
* 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.
2018-09-18 14:25:19 -07:00
Grant Rodgers 6f0348fb69 Rename Targettable to Targetable (#73) 2018-09-18 12:47:18 -07:00
Scott Nichols 67830c7a64 Adding common condition status. (#66)
* 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.
2018-09-17 12:33:18 -07:00
Matt Moore 9a13caa7a1 WIP Define a package with which to support duck typed definitions. (#71)
This also sketches out the skeletons for Targettable, Subscribable, and Conditions.
2018-09-15 19:08:17 -07:00
Scott Nichols f0ec8c5ac7 Adding ViaIndex, ViaKey, ViaFieldIndex, ViaFieldKey to FieldErrors (#55)
* 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
2018-09-14 21:07:17 -07:00
Ville Aikas 760afb6c09 cleanup (#57) 2018-08-30 09:36:12 -07:00
Zhimin Xiang 62d2560a1f Add Istio DestinationRule and Policy into Istio apis and clients (#43)
* initial draft

* fix incorrect dependency on knative/serving

* 1. Move StringMatch from istio/v1alpha3 to istio/common/v1alpha1. 2. Add field excludedPaths into Policy

* fix typo
2018-08-22 16:16:59 -07:00
Matt Moore bc264c290f
Add deepcopy-gen for VolatileTime. (#42) 2018-08-09 16:32:03 -07:00
Matt Moore f2beac9894
Move VolatileTime into knative/pkg (#40) 2018-08-09 15:58:51 -07:00
Scott Andrews a088fee622 Add Istio client from knative/serving (#35)
* 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
2018-08-03 16:14:10 -07:00
Scott Nichols 5182837041 flipped the error text around. fixed. (#36) 2018-08-02 13:13:38 -07:00
Scott Nichols c1e9219cee Adding more field errors. (#34)
* Adding mutually exclusive fields error.

* Adding ErrMissingOneOf, ErrMultipleOneOf, ErrInvalidParameterName

* Adding gitignore.

* Change to ErrInvalidKeyName.

* Use ... semantic.

* those pesky newlines.
2018-08-02 10:05:37 -07:00
Matt Moore 84f0a719d7 Add comments to exported error helpers. (#20)
Noticed via the go report!
2018-07-26 16:40:35 -07:00
Matt Moore 945c05cc41
Bring in the API utilities from `pkg/apis/serving/v1alpha1` used for validation and defaulting in the webhook. (#13)
Fixes: https://github.com/knative/pkg/issues/12
2018-07-26 12:14:57 -07:00