Commit Graph

36 Commits

Author SHA1 Message Date
Matt Moore a5a847fd5c Add a GetCondition method to Status (#336)
I wanted this when rewriting the Pipeline e2e test in Serving to use the dynamic client and checking status via this duck type.

See here: b0ad29dbc8/test/e2e/build_pipeline_test.go (L84)
2019-03-23 11:28:48 -07:00
Scott Nichols 915415e7be Need to use patch merge for conditions. (#328)
* Need to use patch merge for conditions.

* use correct package.
2019-03-18 14:21:45 -07:00
Scott Nichols 587fb819f4 Add back KResourceStatus so eventing master can build serving 0.4 (#325)
* Add back KResourceStatus so eventing master can build serving 0.4

* update codegen.
2019-03-18 10:59:46 -07:00
Matt Moore 374ae9eb1f Expand the Conditions duck type to also encompass ObservedGeneration. (#324)
With this, the expectation is that folks can embed the following in
the status of their resource:

```go
type FooStatus struct {
	duckv1alpha1.Status `json:",inline"`

	// other fields
}
```

`ObservedGeneration` is important to the usefulness of our standard
conditions because `{Ready,Succeeded}: True` is only meaningful when
`.status.observedGeneration == .metadata.generation`.

When `.status.observedGeneration != .metadata.generation` it indicates
that the controller has not yet attempted to reconcile a change in the
desired state of the world (aka `spec:`).
2019-03-17 16:56:45 -07:00
Dave Protasowski 0183bf9cdc Drop spec.generation support (#234)
* Drop webhook logic to increment spec.generation

With Kubernetes 1.11+ metadata.generation now increments properly
when the status subresource is enabled on CRDs

For more details see: https://github.com/knative/serving/issues/643

* Drop the generational duck type
2019-02-14 08:29:45 -08:00
Victor Agababov ac1f818227 remove the redundant receiver (#271) 2019-02-11 13:39:42 -08:00
Victor Agababov 267197692a Use the k8s sets for the code that is actually set of strings (#261) 2019-02-04 14:35:41 -08:00
Matt Moore 298debc821 Make "Severity: Error" conditions less scary. (#255)
This restores the appearance of "terminal" conditions to what is was prior to the separation of "terminal" and "non-terminal" conditions.

Terminal conditions with an "Error" severity will simply omit the field.

This keeps coming up, and came to a head when both Evan and Ville bugged me about it in the same day.

Fixes: https://github.com/knative/serving/issues/2507
2019-01-29 22:12:37 -08:00
Victor Agababov a330baa9b0 Grep fix formatting issues (#233)
* Some fixes to the spoof.go and exporter.go

While reviewing some other CL, I saw some avenues for improving
spoof.go, to log the URL that's being fetched, which would help in test
debugging and to use switch construct, rather than nested if's.

While testing the change, I noticed some shifty loggin from the
exporter, so I fixed that as well while I was there.

* Continuation of the previous cleanups.

* Fix the issues with formatting by executing a grep

* and fix compilation error

* lowercase error

* fix the newly changed unit test
2019-01-18 14:33:32 -08:00
Markus Thömmes 076ebf4e56 Fix another dependents mutation in the conditions. (#231) 2019-01-17 17:13:31 -08:00
Dave Protasowski cba7bf4a22 conditions implementation no longer mutates the underlying dependents array (#229) 2019-01-16 11:35:31 -08:00
Dave Protasowski d6a2e27f7b 🦆 Duck Typing - add a ConformsToType helper (#220)
* duck typing - add a ConformsToType helper

Unlike VerifyType, ConformsToType will return the following:
- an error when any marshalling/unmarshalling fails
- false when the concrete type does not implement the duck type
- true when the concrete type implements the duck type

* use knative/pkg kmp to handle panics raised by go-cmp
2019-01-09 19:58:42 -08:00
Matt Moore 0e41760cea Undo the patch sorting. (#192)
My prior change added sorting to the duck.CreatePatch method to try and stabilize the result of jsonpatch.CreatePatch, which is otherwise non-deterministic (probably walking a map?).

My bad assumption was that the patch operations this generated wouldn't conflict, e.g. it should use `replace` vs. `remove` and `add`.

Clearly this was bad because we start getting really strange errors trying to import this into knative/serving, e.g.
https://gubernator.knative.dev/build/knative-prow/pr-logs/pull/knative_serving/2646/pull-knative-serving-integration-tests/1070435951391543298/
2018-12-05 15:04:26 -08:00
Matt Moore c267dfecb7 This exempts defaulting from the rules governing field immutability. (#191)
Immutable fields with default values may now be changed iff they change is to populate their default value.  This is to support defaulting in the scenario where an object was created long ago and a new field (with a default!) is added.  When controllers attempt to mutate the object status today, this would create a webhook rejection!  With this change, we compare against a freshly defaulted "old" object to exclude newly defaulted fields from the immutability check.

We saw this in knative/serving for the newly added TimeoutSeconds field in Revision (otherwise immutable), which I believe it leading to upgrade testing flakes since post-upgrade Revision status updates will fail.
2018-12-05 13:40:26 -08:00
mattmoor-sockpuppet d99eb0732f Run gofmt (#171)
Produced via: `gofmt -s -w $(find -name '*.go' | grep -v vendor)`
2018-11-26 07:18:22 -08:00
Matt Moore 4b704fa794 Update the ConditionSet to support non-terminal conditions. (#161)
* Update the ConditionSet to support non-terminal conditions.

This change updates the `ConditionSet` datatype to treat the set of conditions that it is initially supplied with as the set of "terminal" conditions, where as before:
1. If all `True`, results in `Ready=True`
2. If any `False`, results in `Ready=False`
3. Otherwise, `Ready=Unknown`

However, in additional to this initial "terminal" set, other conditions may be set that are "non-terminal" and have no influence over the "happy" condition (e.g. `Ready`).

Related to: https://github.com/knative/serving/issues/2394

* Add severity handling to ConditionSet.

This adds a Severity field to our common Condition type, as outlined [here](https://github.com/knative/serving/issues/2394#issuecomment-436806801).

The only way Severity is populated in this change is:
 * Terminal conditions (passed at initial construction) always result in `severity: Error`,
 * non-Terminal conditions (added outside initial set) always result in `severity: Info`.

We should think about how we want to update the `Condition{Set,Manager}` interfaces to surface more control (e.g. `severity: Warning`).
2018-11-08 15:47:44 -08:00
Evan Anderson a8160c7d72 Clean up eventing duck types (#153)
* Clean up eventing duck types.

* Introduce Addressable to unify delivery ducks.
* Remove Subscribable and Channelable (moved to knative/eventing).
* Mark Sinkable and Targetable as retired in favor of Addresable &
  annotations for Callable.

See https://docs.google.com/document/d/1xu18lprM8EFknqrsyZeNgYX2sLE13hfT2UKlYfdxv1g/edit#
for interface/naming details.

* Keep targetable as retired until serving stops using it.
2018-11-02 10:59:35 -07:00
Evan Anderson 82424e6283 Fix a typo in Implementable (#152) 2018-11-01 07:24:34 -07:00
Gregory Haynes 594df37bfd Add support for StrategicMergePatch to duck (#145)
K8s fake clients only support StrategicMergePatches so we should be
creating patches in this format.

Fixes #144
2018-10-26 17:06:32 -07:00
Adam Harwayne 79a09989e6 Make Channelable match the definition in https://github.com/knative/eventing/pull/482. (#134) 2018-10-26 09:13:32 -07:00
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
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
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
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
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