Commit Graph

1313 Commits

Author SHA1 Message Date
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 4da41e302a Bump the sleep in the controller testing. (#88)
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
2018-09-24 07:49: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
Matt Moore 28fe5a05de Don't generate clients for apis/duck (#82)
... they are not real types.

Fixes: https://github.com/knative/pkg/issues/75
2018-09-20 14:56: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
jonjohnsonjr 2a7e950c4e Rename kmeta.NewOwnerReference to NewControllerRef (#70)
This is more accurate, since we're creating a controller ref (and keeps
the naming consistent with metav1).

Also, adds a test!
2018-09-13 15:01:16 -07:00
jonjohnsonjr bfddf2d91b Introduce an OwnerRefable interface (#69)
* 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
2018-09-13 14:14:16 -07:00
Matt Moore d14ed384b0 Switch kmeta/labels to use metav1.ObjectMetaAccessor (#68) 2018-09-13 11:29:16 -07:00
Matt Moore 5f353e5de8 Create a kmeta package for libraries acting on ObjectMeta. (#67)
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.
2018-09-13 10:45:16 -07:00
Dave Protasowski 8fc80deb20 Few changes to the configmap package (#59)
* 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
2018-09-12 07:42:16 -07:00
Dave Protasowski 0122abd983 The test logger will now log the correct caller (#63)
Previous, since we weren't skipping, the logged caller
would be 'logging.go'
2018-09-06 14:16:14 -07:00
srinivashegde86 e7a4b0d534 Dont call flag.parse in pkg/test (#62)
* Dont call flag.parse in pkg

* Remove unused import
2018-09-06 10:06:14 -07:00
Adriano Cunha b2135236d0 Update test-infra dependency (#61)
Includes:
* fixes to `library.sh` in order to have some `hack` scripts working again;
* better checking of PRs where presubmit tests are unnecessary;
2018-09-05 06:57:14 -07:00
srinivashegde86 382a2bff0a Make kube_checks generic so that it can be used in serving (#58)
* Make kube_checks generic

* Use logging lib in cleanup
2018-08-31 16:01:12 -07:00
Ville Aikas 760afb6c09 cleanup (#57) 2018-08-30 09:36:12 -07:00
Adriano Cunha eedc0a939d Make verify-codegen.sh compatible with OS X (#54)
OS X's `mktemp` has no `-p` flag.
2018-08-26 08:42:02 -07:00
srinivashegde86 6eff182b87 Remove docker repo from e2e flags (#53) 2018-08-24 13:44:59 -07:00
Adriano Cunha 4be5c07977 Vendor the test-infra scripts (#52)
* 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.
2018-08-23 21:30:59 -07:00
srinivashegde86 8c687df30f Update WaitForEndpointState to return response (#51)
* Update WaitForEndpointState to return response

* remove extra vars
2018-08-23 13:42:59 -07:00
srinivashegde86 8f6a3be149 Update knative/pkg/test (#50) 2018-08-23 12:03:59 -07:00
Matt Moore 3ca427071d Add a logkey for the reconcile key. (#49)
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.
2018-08-23 09:48:59 -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
srinivashegde86 f4a77d7708 Add a common test clients file (#46)
* Add the common test client

* Update vendor dirs

* Add blank lines in boiler plate doc
2018-08-20 16:10:58 -07:00
srinivashegde86 450739d6f8 Add common test logging module (#45)
* Add common test logging module

* Update references to logging lib

* Add error functions
2018-08-20 16:04:59 -07:00
Scott Nichols a3bc2db77a Remove strict name metadata check to be shareable in eventing (#44)
* Do not valdiate name meta for all objects.

* Remove the test too.
2018-08-14 08:45:57 -07:00
srinivashegde86 8bdbf4eeb9 Add the common test e2e files (#39)
* Add the common test e2e files

* Update deps

* Add the constants and remove serving related methods
2018-08-13 11:28:56 -07:00
Matt Moore bc264c290f
Add deepcopy-gen for VolatileTime. (#42) 2018-08-09 16:32:03 -07:00
Matt Moore 7a0c09e11a
Support multiple group/kind contexts in shared webhook. (#41)
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.
2018-08-09 16:00:55 -07:00
Matt Moore f2beac9894
Move VolatileTime into knative/pkg (#40) 2018-08-09 15:58:51 -07:00
Matt Moore 3b51a7246c Update to the 1.11 client libraries. (#38) 2018-08-06 09:54:11 -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 bf6f9e373f Move our base controller infrastructure into knative/pkg. (#33)
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
2018-08-01 14:32:37 -07:00
Matt Moore fdf2fdcd93 Move the test resource out of `./webhook`. (#32)
This is so that other things can more naturally write tests using this same test resource.
2018-07-31 16:02:37 -07:00
Shashwathi bba99e266c Use fallback named logger (#30) 2018-07-31 14:19:37 -07:00
Shashwathi 9a6f5abda8 Use more verbose error msg (#31) 2018-07-31 09:38:37 -07:00
Yanwei Guo 94bc05ad25 Add yanweiguo as owner of logging directory (#29) 2018-07-30 21:34:37 -07:00
Matt Moore 484160f313 Set up issue and PR templates for pkg. (#28)
Fixes: https://github.com/knative/pkg/issues/10
2018-07-30 13:09:36 -07:00