Commit Graph

290 Commits

Author SHA1 Message Date
Victor Agababov 3a7a787c42
Fix the comment for volatile time (#1315)
And provide a UT and an example how to do this with go-cmp
2020-05-08 10:20:45 -07:00
Weston Haught b559da3646
Generate common logic for krshaped resources (#1311)
* generate krshaped logic

* add logic to the tag

* Update injection/README.md

Co-authored-by: Matt Moore <mattmoor@vmware.com>

* move var to reconciler

Co-authored-by: Matt Moore <mattmoor@vmware.com>
2020-05-08 10:00:45 -07:00
Jason Hall ae0b7dda87
Document VolatileTime (#1313) 2020-05-08 09:39:45 -07:00
Weston Haught c88f43eed9
Create a common method for processing reconciliation on generic KRShaped (#1284)
* Split KResource into a file. Include an interface.

* Update apis/duck/v1/kresource_type.go

Co-authored-by: Matt Moore <mattmoor@vmware.com>

* type

* rename to KRShaped

* Create common logic for bumping obsgen

* fix typo

* remove interface cast

* missed a spot

* Update to use ObjectMetaAccessor

* switch alias to duckv1

* fix var names

* include a reason

* Switch to preprocess

* rename variable from new to resource

* Create a table style test

* missed a spot

* update deps

* fix nits

* fix gomod deps

* update with new KRshaped

* Update reconciler/reconcile_common_test.go

Co-authored-by: Victor Agababov <vagababov@gmail.com>

* Update reconciler/reconcile_common_test.go

Co-authored-by: Victor Agababov <vagababov@gmail.com>

* Update reconciler/reconcile_common_test.go

Co-authored-by: Matt Moore <mattmoor@vmware.com>

Co-authored-by: Matt Moore <mattmoor@vmware.com>
Co-authored-by: Victor Agababov <vagababov@gmail.com>
2020-05-06 17:10:44 -07:00
Weston Haught 3769cd27e5
Switch KRShaped interface to retrieve entire condition set (#1307)
* Switch interface to retrieve entire condition set

* fix method under test

* type
2020-05-06 14:53:44 -07:00
Weston Haught 1099bd14ba
Include GetTopLevelConditionType for KRShaped (#1298)
* Include GetHappyConditionType for KRShaped

* Rename to GetTopLevelCondition
2020-05-05 14:22:44 -07:00
Weston Haught 0605de9264
Make example types KRShaped (#1288)
* make pkg example types KRShaped

* Fix comments

* Switch to the ObjectMeta standard accessor

* Keep pointers around
2020-05-05 10:50:44 -07:00
Weston Haught 4a2ba059b0
Create an interface for retrieving duck-type fields (#1275)
* Split KResource into a file. Include an interface.

* Update apis/duck/v1/kresource_type.go

Co-authored-by: Matt Moore <mattmoor@vmware.com>

* type

* rename to KRShaped

Co-authored-by: Matt Moore <mattmoor@vmware.com>
2020-05-04 11:09:43 -07:00
Ville Aikas 1ebb4d56f7
populate the v1alpha1.Hostname from the URI as per the spec (#1264) 2020-04-29 16:34:42 -07:00
Victor Agababov 23f2fed590
Skip doing any work if `Also` receives no errors (#1256)
* Skip doing any work if Also receives no errors

1. if no errors are passed skip doing stuff (checks, allocations, etc)
2. if there's one error passed and it's empty (the same)
  - this is a quite popular pattern where in API validation we do
    `x.Also(validateY())` and if that succeeded then it'll be an empty
    error. Which is in reality most of the time.
3. Improve tests by better printing
4. better test coverage shows commutativity of Also(a, b) and
   Also(a).Also(b)

* fix flow
2020-04-28 12:03:51 -07:00
Markus Thömmes d29cf98a77
Assorted linting fixes. (#1249)
* Remove unused code.

* Use raw strings to avoid escaping.

* Remove unneeded type conversions.

* Preallocate slices where possible.

* Use semantic equality in psbinding reconciler.
2020-04-28 08:20:51 -07:00
Victor Agababov 8ddda31a35
Some fixes we did in server upstream to pkg (#1244)
* Some fixes we did in server upstream to pkg

- reduce formatting calls where they are not necessary
- remove casts where they are not necessary
- switch to consts where possible.

* nit

* 1more
2020-04-24 15:03:49 -07:00
Antoine Cotten 9320e44d1b
Allow retry of informer cache init upon error (#1221)
* Make informer cache initializations retriable on error

If the first initialization fails, allow the informer cache
initialization to get retried at a later point instead of caching the
error.

* Update cache tests

* Rename 'result' type to 'informerCache'
2020-04-17 09:02:48 -07:00
whaught 9d7c06b6ab
Allow Delete verb on validation callbacks (#1219)
* Create IsInDelete context

* Set up context with WithinDelete

* Test for callback delete

* fix subresource update

* Return oldObj for deletes

* include delete in webhook config

* include delete in unit test

* don't log on delete
2020-04-16 18:30:48 -07:00
Evan Anderson 0c36abbff9
Move duck typing document to markdown (#1184) 2020-04-07 07:59:00 -07:00
whaught d22642244e
Allow Unstructured callback from Validating Webhook (#1172)
* Add new callback pattern to pkg

* include the context

* typo

* Remove the empty instance of unstructured

* initialize the unstructured var

* Eliminate the unneeded pointer

* Pass a pointer to unstructured callback

* Create a validation specific context struct

* Move callback tests to own unit test case

* Switch from converting to decoding

* Update webhook/resourcesemantics/validation/validation.go

Co-Authored-By: Victor Agababov <vagababov@gmail.com>

* don't wrap context and include params

* split validation files

* include 2020 copyright

* include unit test for WithKubeClient

* Don't bother updating copyright date

* Inclue a unit test for panic

* Move dryRun to context

* Include context dry run unit test

* put the request operation in the context

* eliminate circular dep

* move kubeclient test out of context_test

* dont bother iterating callback map

* Callback takes a list of supported verbs

* Remove extra type

* Ensure Callback interface is public

* Alias Operation into validation

* alias Operation right in Webhook

* Update webhook/resourcesemantics/validation/validation_admit.go

Co-Authored-By: Victor Agababov <vagababov@gmail.com>

* Update webhook/resourcesemantics/validation/validation_admit_test.go

Co-Authored-By: Victor Agababov <vagababov@gmail.com>

* Update webhook/resourcesemantics/validation/validation_admit_test.go

Co-Authored-By: Victor Agababov <vagababov@gmail.com>

* Update webhook/resourcesemantics/validation/validation_admit.go

Co-Authored-By: Victor Agababov <vagababov@gmail.com>

* Update webhook/resourcesemantics/validation/validation_admit.go

Co-Authored-By: Victor Agababov <vagababov@gmail.com>

* Update webhook/resourcesemantics/validation/validation_admit_test.go

Co-Authored-By: Victor Agababov <vagababov@gmail.com>

* correct parens

* minor style fixes

* Rename Callback to Func

* Fix build error

* Switch callback to take a list with a factory

* keep descriptive names

* update comment

* Drop pointer, correct comments

* Add a unit test to disallow duplicate verbs

* fix comments, struct{} for set

* switch to variadic arg for NewCallback

Co-authored-by: Victor Agababov <vagababov@gmail.com>
2020-04-06 12:22:19 -07:00
Kenjiro Nakayama fcff978f32
Do not set to unknown status when all dependents passed happy check (#1187)
* Do not set to unknown status when all dependents passed unhappy check

`accessor.GetConditions()` in `findUnhappyDependent()` gets status
filed from runtime. So, if an object has following status:

```
  status:
    address:
      url: http://hello-example.default.svc.cluster.local
    conditions:
    - lastTransitionTime: "2020-04-02T09:49:03Z"
      status: "True"
      type: AllTrafficAssigned
    - lastTransitionTime: "2020-04-02T09:49:03Z"
      message: autoTLS is not enabled
      reason: AutoTLSNotEnabled
      severity: Info
      status: "True"
      type: CertificateProvisioned
    - lastTransitionTime: "2020-04-02T09:49:05Z"
      status: "True"
      type: IngressReady
    - lastTransitionTime: "2020-04-02T09:49:05Z"
      status: "True"
      type: Ready
```

`accessor.GetConditions()` returns AllTrafficAssigned,
CertificateProvisioned, IngressReady (and Ready).

Then, current code (`len(r.dependents) != len(conditions)`) sets to
Unknown if all conditions are not unhappy. However, it does not work
if we added a new dependent and downgraded the cluster because
the number of dependents is less than current status conditions.

If all dependents are verified, it should not set to unknown
status. So, this patch changed it.

* Add unit test
2020-04-04 11:10:18 -07:00
Scott Nichols 8a6d25b309
Generate reconcilers for resources out of tree. (#1175)
* genreconciler:nonNamespaced

* Adding a force-kinds flag to the reconciler generator to allow us to generate reconcilers for non-owned types.

* force-kinds --> force-genreconciler-kinds

* some minor nits with the generators for non-knative types needed to be removed.

* remove whitespace

Co-authored-by: Nacho Cano <nachoacano@gmail.com>
2020-03-25 11:34:51 -07:00
Ignacio (Nacho) Cano 381424b197
add CloudEventAttributes to duckv1.SourceStatus (#1165) 2020-03-20 09:08:22 -07:00
Kenjiro Nakayama c13e86e2d4
Add MarkTrueWithReason function to ConditionManager (#1148)
* Add MarkTrueWithReason function to ConditionManager

When using `MarkTrue()` function, it does not allow us to add the reason and message.
Also, if we use `SetCondition()` instead, it does not update the happy condtion.

So, this PR adds new `MarkTrueWithReason(reason, message)` function.

* Make test better

* Add unit test for MarkTrueWithReason

* Rename markHappy with recomputeHappiness
2020-03-19 09:36:06 -07:00
Dave Protasowski d771641c91
Fixed #1057 - Rename ConvertUp/Down to ConvertTo/From (#1122) 2020-02-24 09:44:08 -08:00
Dave Protasowski 5bc49f27e6
use interfaces when testing conditions so we don't need versioned methods (#1120) 2020-02-24 09:23:08 -08:00
Scott Nichols d9a38f13e8
Nil check conditions (#1112)
* Realized a corner case on ordering and False > Unknown states.

* add test with unknown fall through.

* I guess some integartions allow nil happy

* add unit tests for GetMessage and GetReason

* all conditons can be nil.

* Search for unhappy dependents.

* update codegen

* Remove KResource from v1alpha1 ducks.
2020-02-20 11:20:06 -08:00
Scott Nichols d38e1f8bde
Realized a corner case on ordering and False > Unknown states. (#1110)
* Realized a corner case on ordering and False > Unknown states.

* add test with unknown fall through.
2020-02-20 06:55:06 -08:00
Scott Nichols 5c9bc970ce
Clear falied propagation status of the top level condition if cleared. (#1108) 2020-02-19 21:16:06 -08:00
Scott Nichols 5d8a01d12c
Implement strongly typed class reconcilers (#1103)
* Implement strongly typed class reconcilers

* document class filters.

* matt is always right
2020-02-19 08:38:06 -08:00
Scott Nichols 72f3cd2bbc
[Genreconciler] Fix group names when client groups differ than their directory name. (#1097)
* looking at annotations for group overrides.

* checkpoint.

* checkpoint

* I think it is correct.

* ok

* trim down the files.

* simulate tekton

* working test out of checkin

* remove test client

* update docs

* and test.

* lint

* it ok

* update codegen
2020-02-18 17:14:59 -08:00
Matthias Wessendorf d8b36f3593
💄 updating comment on Destination, because it's no longer a domain name, but merely a URI (#1094)
Signed-off-by: Matthias Wessendorf <mwessend@redhat.com>
2020-02-13 23:31:40 -08:00
cshou 1cc3c3e852
Update jsonpatch lib that correctly handle object removal (#1078)
* update jsonpatch lib

* add more patch tests for removal
2020-02-12 08:27:22 -08:00
Scott Nichols 32ea845815
Fix a upconvert with empty url (#1064) 2020-02-07 10:15:14 -08:00
Scott Nichols 87875e3b42
found a defaulting bug in the converter for empty addressables. (#1062) 2020-02-06 17:47:32 -08:00
Victor Agababov 8c2e0012c3
No reason to get parent NS if we're not gonna use it. (#1055)
and add a comment for the public method
2020-02-06 09:42:32 -08:00
Ville Aikas 4ec5e09f71
check KReference namespace matches parent. Allow escape hatch. (#1052) 2020-02-05 08:04:31 -08:00
Victor Agababov 0264117c2b
Some nit cleanups (#1040) 2020-02-03 16:56:30 -08:00
Ville Aikas 95163c65ac
Rename KnativeReference to KReference (#1039) 2020-02-03 12:58:30 -08:00
Ville Aikas d5698e90e2
make namespace optional so existing objects keep working (#1034) 2020-02-02 22:17:30 -08:00
Ville Aikas 99abcc2ff5
add SetDefaults from parent (using context), change Destination to us… (#1031)
* add SetDefaults from parent (using context), change Destination to use KnativeReference

* address pr comments, change address resolver to use kref
2020-02-01 11:59:29 -08:00
Ville Aikas aebcdbd5f3
add KnativeReference (#1030)
* add KnativeReference

* fix copyright year
2020-01-31 13:22:28 -08:00
Victor Agababov 01017dcbf1
Fix the URL errors for go1.14 (#1027)
The error formatting changed, so update the tests so they work with both 1.13
and 1.14.
2020-01-31 11:12:28 -08:00
Dave Protasowski 4b31f15f21
include testing helpers to fuzz our API types and perform some roundtrip testing (#1010)
* include facilities that make roundtrip testing API types possible

* include helpers for fuzzing apis.URL and status conditions
2020-01-28 06:58:26 -08:00
Dave Protasowski 5ff923b836 conditions were being duplicated since we broke vs. continuing (#1009)
* conditions were being duplicated since we broke vs. continuing

* pr feedback

* butter finger
2020-01-24 07:23:24 -08:00
Dave Protasowski 4e81bc3c32 status.ConvertTo can optionally accept predicates (#1003)
the intent is to allow the inclusion of addition ConditionTypes to be copied over if a
a predicate returns true
2020-01-21 18:29:23 -08:00
Dave Protasowski 55e632ca67 add helpers to convert objects through Convertible proxies (#1002) 2020-01-21 14:25:24 -08:00
Dave Protasowski f72610ea73 unit test to ensure semantic equality func is registered for apis.URL (#988) 2020-01-11 18:40:59 -08:00
Dave Protasowski fb00bf88a3 Provide an semantic equality func for apis.URL (#987)
url.URL has an unexported type (UserInfo) which causes semantic
equality to panic unless we add a custom equality function
2020-01-10 10:25:57 -08:00
Scott Nichols 298f22bea6 update boilerplate to use 2020 (#979) 2020-01-07 16:04:51 -08:00
Ville Aikas 7c7512aecf add ability to opt-out of bindings (#970)
* add ability to opt-out of bindings

* I guess a year changed...

* had opt-in / opt-out backwards

* add unit test for contexts, fix comment

* clarify comments

* remove Binding from method/const names since already in bindings package
2020-01-07 08:56:51 -08:00
capri-xiyue fa1c639c93 Add helper methods in conditon_set (#965)
* added isUnknown in condition_set

* added IsFalse for condition set

* added GetHappyCondition

* modified comments

* modified the code based on cr

* renamed the method and removed isXXX() methods

* modified comments
2020-01-06 08:00:49 -08:00
coryrc 9d8b936ca0 Switch *testing.T uses to equivalent interface + structured logging (#935)
Working to introduce structured logging to our tests. See #907

This work allows these test functions to be called by objects other
than *testing.T. The t.Error() calls are made compatible with
structured logging (wrapping Zap sugared logger calls) or code using
testing.T.
2019-12-13 10:22:54 -08:00
Matt Moore 891c2876dd Implement a base library for implementing "Pod Spec"-able bindings. (#915)
This PR adds facilities to make it easier to create both components of a Binding
over "Pod Spec"-able resources.  Rather than rehashing it all here, please look
at `./pkg/webhook/psbinding/README.md` for more details.
2019-12-02 08:58:34 -08:00
Ville Aikas cac31abb7f Change URIFromDestinationV1 to return apis.URL instead of string (#909) 2019-11-27 13:13:22 -08:00
grac3gao 46cfce8d99 Add check in informer to make controllers work when process invalid resources (#880)
* #2047 sources-controller can't recover from faulty sink (in eventing)

* #2047 sources-controller can't recover from faulty sink (in eventing)

* add unit test

* change after review

* change after review-2

Co-Authored-By: Victor Agababov <vagababov@gmail.com>
2019-11-26 14:16:21 -08:00
Slavomir Kaslev ddf3968b65 Migrate pkg to istio.io/client-go apis (#882)
* Add istio api packages from istio.io/api and istio.io/client-go

* Codegen istio client for apis from istio.io/client-go

* Remove our istio apis
2019-11-26 11:41:21 -08:00
Matt Moore 7325e901c0 Format markdown (#904)
Produced via:
  `prettier --write --prose-wrap=always $(find -name '*.md' | grep -v vendor | grep -v .github)`
/assign n3wscott
2019-11-26 10:28:21 -08:00
Matt Moore 9f41433241 Add a simple ToUnstructured method for converting our types to unstructured. (#900)
This adds a ToUnstructured method to complement the FromUnstructured method
we have had for some time.  The ToUnstructured method is effectively scoped
to Knative-style types since we expect it to implement both kmeta.Accessor
and kmeta.OwnerRefable in order to ensure that the TypeMeta is always
properly populated.
2019-11-26 10:05:21 -08:00
Matt Moore 6305a6322f Fix the serialized name of the spec field (oops) (#899) 2019-11-25 13:24:21 -08:00
Matt Moore b75a4bf672 This adds a duck type representing the common shape for Bindings. (#898)
For more information, see [here](https://docs.google.com/document/d/1t5WVrj2KQZ2u5s0LvIUtfHnSonBv5Vcv8Gl2k5NXrCQ/edit?ts=5dce0223#heading=h.lnql658xmg9p).
2019-11-25 13:10:21 -08:00
Matt Moore 43ca049cdb Reduce the boilerplate for setting up duck.InformerFactory's. (#896)
This augments the injection codegen with the capability to produce a duck.InformerFactory
attached to context for each type that we process.

Now a `duck.InformerFactory` for "Addressable" can be produced by "Get"ing it from the context.

This is triggered by placing `// +genduck` on the type that implements `duck.Implementable`.
2019-11-25 09:57:10 -08:00
Matt Moore d752898438 Make PodSpeccable a real thing (#884) 2019-11-18 08:02:08 -08:00
Matt Moore 4836f680bb Split the resource semantic webhooks into separate AdmissionControllers (#848)
By combining our validation logic into our mutating webhook we were previously allowing for mutating webhooks evaluated after our own to modify our resources into invalid shapes.  There are no guarantees around ordering of mutating webhooks (that I could find), so the only way to remedy this properly is to split apart the two into separate webhook configurations:
 - `defaulting`: which runs during the mutating admission webhook phase
 - `validation`: which runs during the validating admission webhook phase.

The diagram in [this post](https://kubernetes.io/blog/2019/03/21/a-guide-to-kubernetes-admission-controllers/) is very helpful in illustrating the flow of webhooks.

Fixes: https://github.com/knative/pkg/issues/847
2019-11-14 16:51:02 -08:00
Matt Moore 285df36be4 Move Destination under knative.dev/pkg/apis/duck/v1. (#851)
Destination sits in a strange versioned directory without a group under APIs.  Destination is in fact part of our duck type space, so it belongs under the `duck` group.  This moves the definition (previously v1alpha1) to `v1` because it is referenced from source types that have been designated `v1`.
2019-11-06 15:59:02 -08:00
Antoine Cotten 1cc9641c28 Remove openapi-gen annotations (#775) 2019-11-05 13:03:27 -08:00
Markus Thömmes 56c2594e4f Assorted linting fixes. (#840)
* Remove unused code.

* Remove unneeded loops.

* Remove unneeded Printf calls.

* Use time.Since instead of time.Now().Sub.

* Remove unused values.

* Rename error variable according to conventions.

* Return error last.

* Simplify array allocations.

* Remove leaky ticker.

* Remove Yoda conditions.

* Remove deprecated function to talk to GKE.

* Remove dot import.

* Remove empty critical section and replace with a channel operation.

* Add linter directives to explicitly state wanted weirdness.

* Update deps.

* Fix broken line.
2019-11-01 12:49:12 -07:00
Scott Nichols 878b391a68 duckument the ducktypes. (#808)
* duckument the ducktypes.

* fix status.sinkUri.
2019-10-25 11:23:35 -07:00
Adam Harwayne 2a3fc371d3 Add Destination.GetRef() to abstract out the ref vs deprecated ref. (#801)
* Add Destination.GetRef() to abstract out the ref vs deprecated ref.

* No longer a pointer method.
2019-10-24 15:30:35 -07:00
Ville Aikas 0c92be1883 add method to Destination validation that disallows Deprecated* fields (#800) 2019-10-24 14:58:34 -07:00
capri-xiyue a9458a30c0 add DeprecatedObjectReference in Destination to support backwards compatibility (#790)
* added DeprecatedObjectReference as a field in Destination to support backwards compatible

* updated code-gen

* added four deprecated fields
2019-10-24 12:55:34 -07:00
mattmoor-sockpuppet 2d54fc909d golang format tools (#791)
Produced via:
  `gofmt -s -w $(find -path './vendor' -prune -o -type f -name '*.go' -print))`
  `goimports -w $(find -name '*.go' | grep -v vendor)`
/assign mattmoor
2019-10-23 13:37:29 -07:00
Evan Anderson ea367c1342 Add utility methods for api.URL (#785)
* Add IsEmpty and HTTP/HTTPS constructors, simplify tests.

* Simplify remaining construction of URLs in tests with struct initialization.

* Reverse `nonEmpty` since most cases are now non-empty.

* Update initial tests. Also fix a bug in URL.String() and update test.
2019-10-21 19:11:25 -07:00
capri-xiyue 5dcae770a9 change Destination api and addressable resolver, fixed unit tests and… (#774)
* change Destination api and addressable resolver, fixed unit tests and added more unit tests

* make validateDestination visible

* rename error msg, added comments, added unit tests

* reformat error msg and change positive case order

* modified error msg when ref is not valid

* fixed typo
2019-10-21 14:42:25 -07:00
Matt Moore e4ac97c252 Update our dependency on K8s libs to 1.15.3 (#686)
With a minimum K8s version of 1.14 (starting in 0.10), 1.15.3 puts us in the center of the +/-1 version window of support.
2019-09-18 13:36:48 -07:00
Jean-Rémy Bancel 2d6c3459ce Use *url.URL instead of string in request.go. (#670) 2019-09-18 11:56:47 -07:00
Dan Gerdesmeier d8d1bc2718 Move duck patch helper function from Knative Serving to pkg (#681)
We have been maintaining a copy of this helper function in the Knative
Serving tests. Moving it here and adding tests so it can be used more
generally. The function allows creating a []byte patch without having to
check two levels of error conditions.
2019-09-15 21:35:40 -07:00
Kenjiro Nakayama 3415797394 Introduce error util ErrInvalidCombination for invalid combination (#638)
* Introduce error util ErrInvalidCombination for invalid combination

Sometimes valid value becomes invalid value by combination.

example 1. https://github.com/knative/serving/issues/5382
example 2. following combination in `spec.traffic`.

```
  traffic:
  - latestRevision: true
    revisionName: hello-example-dk7nd
    percent: 100
```

But there are no error util for them, so we need to create
custom error like c1583f3045
or `ErrInvalidValue`.

The custom error will make code complicated and `ErrInvalidValue` is
not debug friendly.

To solve it, this patch introduces an util func `ErrInvalidCombination`.

* Introduce ErrGeneric instead of ErrInvalidCombination
2019-09-12 16:44:32 -07:00
mattmoor-sockpuppet ec03725bc7 golang format tools (#647)
Produced via:
  `gofmt -s -w $(find -path './vendor' -prune -o -type f -name '*.go' -print))`
  `goimports -w $(find -name '*.go' | grep -v vendor)`
/assign mattmoor
2019-09-09 07:30:10 -07:00
Toshinori Sugita 774ffb7b16 update links (#646) 2019-09-09 07:02:10 -07:00
Dan Gerdesmeier 5f0515d336 Version condition testing helper functions (#644) 2019-09-08 16:39:06 -07:00
Dan Gerdesmeier a95116ff16 Add Addressable type converters to v1 Addressable (#642)
* Add Addressable type converters to v1 Addressable

v1alpha1 embeds v1beta1 which makes them easily convertible. However, we
cannot embed both v1beta1 and v1 into v1alpha1 easily. Updating to just
use v1 in v1alpha1 is breaking so this change implements converters
to enable moving between v1 and v1beta1/v1alpha1 without having to
implement the logic in every client needing to convert.

* Use apis.Convertible interface
2019-09-07 14:59:05 -07:00
Matt Moore d29eb5d70c Cut v1 of the duck types. (#615)
The main pieces of interest here are Addressable and Status.

This is a glorified copy/paste of v1beta1 with `s/v1beta1/v1/g`.
2019-08-28 13:49:42 -07:00
Laszlo Bence Nagy ab6c488967 Add exportTo field to Istio CRDs (#586) 2019-08-27 10:50:40 -07:00
Scott Nichols 85d7d7ec71 correct a unmarshal error for non pointer members of apis.URL if empty string. (#594) 2019-08-22 08:03:34 -07:00
Spencer Peterson 0a0c4972cd Add Destination constructors (#572)
* add helper constructors for destination

* flesh out destination constructors and path appending
2019-08-14 10:48:08 -07:00
Spencer Peterson 6a881edeba document ParseURL breaking the net/url api (#571) 2019-08-14 09:58:07 -07:00
Scott Nichols 11fec633e4 Adding Source ducktype. (#566)
* Adding Source ducktype.

* removing output format for now, revisit if we find more sources and consumers asking for it.
2019-08-13 10:58:06 -07:00
Scott Nichols a690d27530 Missed the deepcopy gen for Destination. Fixed. (#567) 2019-08-09 12:50:04 -07:00
mattmoor-sockpuppet a918c2d8f8 golang format tools (#565)
Produced via:
  `gofmt -s -w $(find -path './vendor' -prune -o -type f -name '*.go' -print))`
  `goimports -w $(find -name '*.go' | grep -v vendor)`
/assign @mattmoor
2019-08-09 12:11:06 -07:00
Scott Nichols 53034608f6 Adding apis/v1alpha1/Destination; future sink and subscriber object. (#561)
* adding apis/Destination; future sink and subscriber object.

* move Destination to a v1alpha1 dir.
2019-08-09 08:16:05 -07:00
Andrew Poydence 972acd413f apis: fix typo in ConditionSet.Manage comment (#551) 2019-07-30 08:52:43 -07:00
savitaashture cb7014ea6e Add validation for creator and lastModifier annotation (#539)
* Add validation for creator and lastModifier annotation

* Add test case for spec changes and /lastModifier updated changes
2019-07-28 21:51:04 -07:00
Spencer Peterson 154a0848d4 test for FieldError.Also(nil) (#545) 2019-07-28 09:36:04 -07:00
Johnu George 86f49e59e0 Implement ClearCondition for ConditionManager (#538)
* Implement RemoveCondition for ConditionManager

This implements RemoveCondition to remove a condition that matches
the condition type. Happy condition is changed appropriately if it
is a terminal and satifies one of the following conditions
1. RemovedCondition is false and happy is false
    Happy can change from false to unknown or true
2. RemovedCondition is unknown and happy is unknown
    Happy can change from unknown to true

* comment edit

* Addresses review comments

* Support only non terminal conditions

* Fix check
2019-07-24 14:22:35 -07:00
Victor Agababov 74c5d67ea0 Fix the issues pointed out by staticcheck (#541)
* Fix the issues pointed out by staticcheck

* review fix
2019-07-23 13:13:36 -07:00
Jin Chi He 76da19bbc6 add openapi-gen=true for some structs (#510) 2019-07-11 21:17:33 -07:00
mattmoor-sockpuppet 1864f499dc golang format tools (#497)
Produced via:
  `gofmt -s -w $(find -path './vendor' -prune -o -type f -name '*.go' -print))`
  `goimports -w $(find -name '*.go' | grep -v vendor)`
/assign @mattmoor
2019-06-27 07:37:08 -07:00
Matt Moore 222dd25986 Migrate pkg to use the knative.dev/pkg import path (#489)
* Manual changes.

* scripted changes.
2019-06-26 13:02:06 -07:00
Ali Ok 9f8e0692b7 #457 Duck type user annotation logic (#467)
* #457 Duck type user annotation logic

* #457 Duck type user annotation logic - tests

* #457 Revert updater annotation key from lastModifier to updater

* #457 Rename HasSpec#GetSpec() to HasSpec#GetUntypedSpec()

* #457 Fix some indentation

* #457 Get group for user info annotations from the request

* #457 Reduce confusuion in webhook testing by using same group
2019-06-24 18:20:05 -07:00
Victor Agababov c2f344436b Better for loop for iterating over the channel (#458) 2019-06-12 13:40:44 -07:00
Matt Moore 262650b2c0 Incorporate the sub-resource context into the context state populated by the webhook. (#442) 2019-06-05 20:36:39 -07:00
Matt Moore 5fe2b490af Add a GetURL helper for consuming Addressable. (#434)
* Add a GetURL helper for consuming Addressable.

* Update apis/duck/v1alpha1/addressable_types_test.go

fix the copyright header

Co-Authored-By: mattmoor-sockpuppet <mattmoor+sockpuppet@google.com>
2019-05-30 07:09:32 -07:00
Adriano Cunha c0132d9dde Update OWNERS to use OWNERS_ALIASES (#422) 2019-05-29 20:04:33 -07:00
Matt Moore 868008d0f8 Implement Addressable v1beta1 to use URL. (#401)
Fixes: https://github.com/knative/pkg/issues/395
2019-05-02 17:46:34 -07:00
Matt Moore 57fd07886b Add support for a structured URL type. (#400)
* Add support for a structured URL type.

This type can be used to accept `url: http://asdf.com` where in code we
get a `url.URL` to interact with.

* Propagate errors parsing, cast pointer instead of copying.
2019-05-01 18:40:33 -07:00
mattmoor-sockpuppet 105f928666 golang format tools (#397)
Produced via:
  `gofmt -s -w $(find -path './vendor' -prune -o -type f -name '*.go' -print))`
  `goimports -w $(find -name '*.go' | grep -v vendor)`
2019-04-28 07:59:30 -07:00
lIuDuI 6916051a96 Using var() block to define variables (#394)
Signed-off-by: xichengliudui <1693291525@qq.com>
2019-04-23 08:53:29 -07:00
lIuDuI c697d0b0e1 Find some duplicate words for "the" and delete them (#392)
Signed-off-by: xichengliudui <1693291525@qq.com>
2019-04-22 10:54:28 -07:00
Scott Nichols 70ab9cc77d Adding Strict Validation based on struct.*Deprecated*Foo (#339)
* have simple tests. working on impl.

* strict setting, reflection based.

* ran codegen.

* adding license.

* update based on feedback and merge better.

* getting closer to something  simpler assuming shallow reflect.

* adding validation test.

* use the json tag.

* Golang things nil typed pointers are not nil.

* Use real value of reflect invalid.

* add a missing test.

* two methods, one for update, one for single check.

* checkdep is now in apis.

* fix pkg.

* Update apis/deprecated_test.go

Co-Authored-By: n3wscott <32305648+n3wscott@users.noreply.github.com>

* add code clarity.

* include inlined struct objects recursively.

* Update commnets and add a flatten error test for inlined.
2019-04-19 09:19:27 -07:00
Dan Gerdesmeier 6fa5cc22e3 Add CheckDisallowedFields (#389)
Adds a new function in FieldErrors for validating against fieldmasks.

See https://github.com/knative/serving/pull/3779 for usage.
2019-04-17 17:51:26 -07:00
Matt Moore efba541fdd Add support for the Istio 1.1 per-route Headers. (#385) 2019-04-15 14:37:00 -07:00
Matt Moore 2adf7f0c98 Add a few more general contexts built in serving. (#384)
Fix the user info annotation bug introduced along with the context stuff.

Fixes: https://github.com/knative/pkg/issues/383
2019-04-11 07:44:59 -07:00
Matt Moore 9eb762fd55 Add ObservedGeneration to what we convert. (#374) 2019-04-09 10:34:58 -07:00
Matt Moore 31649c272a Start to lay the groundwork for Status conversion. (#373)
The backbone of our Condition system is our "happy" condition and
the semantics governing how other subconditions influence that condition.
When looking towards Conversion, it is possible for the set of conditions
to vary between `v1alpha1` and `v1beta1`, but the "happy" condition should
remain consistent across versions.

The main changes:
1. Provide a `ConvertTo` helper for "converting" between `duckv1beta1.Status`
 types in this "lowest common denominator" sense, where we just copy the
 happy condition.
2. When `InitializeConditions()` (plural) is called, seed the initial state
 of sub-conditions from the initial state of the "happy" condition, if True.

This change enables us to completely change the condition space across
versions, while maintaining the consistency of the happy condition.

A couple peripheral changes:
1. Add `context.Context` to the `apis.Convertible` interface.
2. Drop `InitializeCondition()` (singular) from the `ConditionsManager` interface (I don't see any usage outside of this file).
2019-04-09 08:22:59 -07:00
Matt Moore f55c11c3ce ErrInvalidValue support for interface{} (#372) 2019-04-08 18:26:58 -07:00
Matt Moore e0fcca3e1d Enable our OOB error to take raw types. (#371) 2019-04-08 17:49:57 -07:00
Matt Moore 2b574edcd7 Deprecate apis.Immutable and apis.Annotatable. (#368)
This deprecates the `apis.Immutable` and `apis.Annotatable` interfaces,
which were both awkward niche extensions of `apis.Validatable` and
`apis.SetDefaults` for specific contexts that the former set didn't
cover well.

With this change, the expectation is that types that want to check
for immutability will instead access the "baseline" object via the
context from within updates.  For example:

```
func (new *Type) Validate(ctx context.Context) *apis.FieldError {
  if apis.IsInUpdate(ctx) {
    old := apis.GetBaseline(ctx).(*Type)
    // Update specific validation based on new and old.
  }
}
```

For applying user annotations, the type writer can write:

```
func (new *Type) SetDefaults(ctx context.Context) {
  if apis.IsInCreate(ctx) {
    ui := apis.GetUserInfo(ctx)
    // Set creator annotation from ui
  }

  if apis.IsInUpdate(ctx) {
    ui := apis.GetUserInfo(ctx)
    old := apis.GetBaseline(ctx).(*Type)
    // Compare old.Spec vs. new.Spec and on changes
    // update the "updater" annotation from ui.
  }
}
```

One of the key motivations for this refactoring was to enable us
to do more powerful validation in `apis.Validate` beyond the niche
of immutability checking (and without introducing yet-another
one-off niche interface).  In the BYO Revision name PoC I abused
`apis.Immutable` to do more arbitrary before/after validation,
which with this can simply be a part of `apis.Validatable`.

See: https://github.com/knative/serving/pull/3562

The general stance on deprecating interfaces such as these will be
to deprecate them in a non-breaking way (via a comment for now). They
will be hollowed out when the functionality is removed from the webhook,
but left in because of diamond dependency problems.  In this change
we remove the `apis.Annotatable` functionality and deprecate the
`apis.Immutable` functionality.
2019-04-08 10:26:58 -07:00
Matt Moore 42e08a4657 Add the Convertible interface. (#369)
This sketches the "Convertible" interface that @vagababov outlined in
last week's Serving API WG meeting.

See also: https://docs.google.com/document/d/1UFUfwIF4q4r6JVigom0jQivbcI8mFycWPc9z48yjSIc/edit#heading=h.9np2by1b65b
2019-04-08 07:21:58 -07:00
Victor Agababov 4993c57ea3 Share the common parts of Serving ObjectMeta validation (#367) (#370)
This assumes that we want to strictly allow DNS labels in names everywhere.
2019-04-07 15:19:57 -07:00
Matt Moore 21372d06ff Share the common parts of Serving ObjectMeta validation (#367)
This assumes that we want to strictly allow DNS labels in names everywhere.
2019-04-05 15:38:57 -07:00
Thomas Shafer c80cb7dee9 Remove unused receiver name (#366) 2019-04-05 11:01:57 -07:00
Thomas Shafer d5db385fcc Address some lint errors (#351)
* Fix lint error: Remove unused receiver name

* Fix lint error: consistent receiver name

* Update apis/duck/v1alpha1/conditions_types.go
Update apis/duck/v1alpha1/retired_targetable_types.go
Update apis/duck/v1alpha1/legacy_targetable_types.go

Co-Authored-By: trshafer <tshafer@google.com>
2019-04-05 08:52:57 -07:00
Victor Agababov 71f46d3165 Condition checkable utilities (#364)
* add the new files

* checkpoint

* use duck

* test –> testing
2019-04-05 07:26:57 -07:00
Zhimin Xiang ff46edef0a Add CredentialName into Gateway (#360) 2019-04-02 11:10:56 -07:00
Matt Moore 281cda84ce Move Condition stuff to apis, add a v1beta1 Status. (#361)
This moves the common Condition stuff to apis, and creates a v1beta1 form of Status that uses the Condition it defines (changing this in v1alpha1 is too breaking).

There aren't really any meaningful changes in this PR, mostly reorganization.  Enumerating what I did:
1. Copied `condition_set*.go` to `apis/`,
1. Copied the `Condition` portions of `conditions_types.go` to `apis/`,
1. Copied the balance of `conditions_types.go` to `apis/duck/v1beta1/status_types.go`,
1. Changed the parts of the above to reference things in the appropriate new places,
1. Removed the reflection-based `ConditionsAccessor` stuff, implementing it instead on `duckv1beta1.Status`.
1. Incorporate: https://github.com/knative/pkg/pull/358
2019-04-02 09:51:55 -07:00
Thomas Shafer 1d9d8f8871 Fix lint error: Address struct field naming (#352)
Ran ./hack/update-codegen.sh
2019-03-29 10:23:54 -07:00
Victor Agababov b032768e6d Fix v1beta1 deployment to v1 in test (#346) 2019-03-27 13:48:51 -07:00
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
Matt Moore 60fdcbcabd This threads a context.Context through the webhook interfaces we expose. (#332)
Related to: https://github.com/knative/pkg/issues/306
2019-03-21 10:48: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
Stefan Prodan f8007289b2 Add CORS Policy to Istio HTTP route (#294)
Signed-off-by: stefanprodan <stefan.prodan@gmail.com>
2019-03-08 16:35:41 -08:00
Alex DiCarlo cc337f8142 Fix VirtualService tcp and tls definitions (#268)
* Fix VirtualService tcp and tls definitions

* Regenerate deepcopy for istio/v1alpha3

* Remove out of date comment

* Fix up comments
2019-03-08 16:30:41 -08:00
Bob Corsaro 1ed7b993c8 Updates istio HTTPMatchRequest api (#305)
* Updates istio HTTPMatchRequest api

* Updates generated code
2019-03-05 12:19:39 -08: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 1982208dd9 Initial commit for the webhook to set the annotations about mutator. (#275)
* Initial commit for the webhook to set the annotations about mutator.

The user that created or updated the resource will be set in the
annotations.

* update comments

* remove debug logging

* logging :/

* logging :/, returns

* logging :/ III

* error wrap

* simplify test

* rename the test

* add pkg/errors to the deps for better errors

* do not require CRD to implement Annotatable

* review issues

* fix interface as required by review
2019-02-12 21:03:43 -08:00
Victor Agababov ac1f818227 remove the redundant receiver (#271) 2019-02-11 13:39:42 -08:00
mattmoor-sockpuppet 4f143e6ce3 golang format tools (#263)
Produced via:
  `gofmt -s -w $(find -path './vendor' -prune -o -type f -name '*.go' -print))`
  `goimports -w $(find -name '*.go' | grep -v vendor)`
2019-02-07 08:17:41 -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
Victor Agababov 819ebda80c Add `AtIndex` method to deal to attach index at the current error. (#257)
* Add `AtIndex` method to deal to attach index at the current error.

This is useful when we are dealing with primite leaf list (e.g.
a list of strings).
The alternative are
a) creating dummy error and then executing ViaFieldIndex(), which is
plain ugly
b) implementing Validate() on the primitive type via type aliasing and
then collecting errors, which seems an overkill.

In addition it seems ViaFieldIndex was not covered by unit tests,
so I've added one to take care of that.

* implement suggestions from the review

* cleanup

* cosmetic

* cosmetic
2019-01-31 12:47:38 -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
Yaron Schneider f9612ef738 Fix json mismatch in istio pkg (#247)
* corrected suffix

* fixed name
2019-01-28 20:51: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
Victor Agababov 585076ba67 Fix some comments about code comments left from the previous PR. (#196) 2018-12-09 06:42:27 -08:00
Victor Agababov 1f624b77dd Some clean ups in the FieldError code and its tests. (#194)
* Some clean ups in the FieldError code and its tests.

- rename FieldError.getNormalizedError to be normalized:
  - Go kind of discourages GetA() vs A()
  - it's an error, so normalizing itself is also an error, so
    normalizedError() is a tautology at this point
- flatten was doing a[x]=fmt.Sprintf("%s%s", a[x],y), which is a very
  expensive substitution for a[x]+=y
- some minor test cleanups (fix strings, streamline `got, want:=`
  pattern, etc.

* Also make normalize() and merge() operate on pointers.

As the code currently is structured we are doing lots of duplication
and copies of the objects, since we're doing []FieldError throughout
normalize() and merge() even though normalize already returns a copy of
the initial error tree, rather than a list of pointers to existing
errors.

Hence list returned by normalize() and hence merge() can actually be pointer
lists which would save us some CPU and memory.
2018-12-06 17:06:26 -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 973ea220f9 Format markdown (#189)
Produced via: `prettier --write --prose-wrap=always $(find -name '*.md' | grep -v vendor | grep -v .github)`
2018-12-04 14:14:25 -08:00
mattmoor-sockpuppet 0f793b2942 Format markdown (#183)
* Format markdown

Produced via: `prettier --write $(find -name '*.md' | grep -v vendor)`

* Fix issue template
2018-12-03 13:53:25 -08:00