Commit Graph

103 Commits

Author SHA1 Message Date
lichuqiang d247efe41d update EnqueueControllerOf to properly handle Delete (#146)
* update EnqueueControllerOf to properly handle Delete

* update existing test

* add enqueue label tests

* address comments
2018-10-30 07:13:34 -07:00
Scott Nichols 5a67e38d13 Simplify FieldError merging. (#99)
* checkpoint.

* Tried a new way.

* Some more slimplifying based on feedback.

* use bang vs == false.

* not sure why I did not use go style on this forloop, fixed.
2018-10-30 01:20:33 -07:00
Zrss d83605ef7b Add webhook svc name to DNSNames of cert (#140) 2018-10-29 11:16:33 -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
Martin Gencur 7528f768d9 Check error condition when setting default kubeconfig (#142)
* avoid segmentation fault when the user is not returned correctly
2018-10-26 09:17: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 5c809f170b Add logic to check the licenses of our common package (#135)
* Add logic to check the licenses of our common packages.

* Update test-infra.

* Fix the test-infra vendor
2018-10-25 17:37:31 -07:00
akyyy a935e6aaa6 fix flaky test (#138) 2018-10-25 14:44:32 -07:00
Zrss d3fbe1d459 Clean useless unregister mutatingwebhookconfiguration process (#136) 2018-10-25 09:23:32 -07:00
akyyy 10ceeb6163 Add stackdriver exporter support in pkg. (#126)
* update dep golang.org/x/net

* Add stackdriver exporter support in pkg

* fix race and tests

* Use thread safe newMetricsExporter in tests

* address cr comments

* minor fix

* checkpoint

* Address cr comments

* add test for UpdateExporterFromConfigMap

* Move lock position

* add a test case for stackdriver error check

* minor change

* removing one test case since it seems app default creds exists for presubmit tests

* replace promSrvChan with promSrv as cr suggsted

* use a local var server for ListenAndServe

* add getter and setter for shared variables

* add func isMetricsConfigChanged and test

* address cr comments

* Update opencensus-go-exporter-stackdriver to v0.7.0

* Revert "Update opencensus-go-exporter-stackdriver to v0.7.0"

This reverts commit 9825f641f8.

* run update-deps.sh

* merge conflict

* run update-deps.sh

* Update Gopkg.toml so it doesn't have stackdriver exporter

* remove regex for metrics domain at pkg repo per cr comments

* merge conflict
2018-10-24 15:23:31 -07:00
Zrss 2b28d46464 Make clientAuth of webhook server into a configuration option (#125) 2018-10-24 08:42:31 -07:00
Zrss d82a0a3d1c Exit when bootstrap http server of webhook error (#131)
* Exit when bootstrap http server of webhook error

* Clean useless newRunningTestAdmissionController func

* return server.Close() err
2018-10-23 13:56:31 -07:00
lichuqiang 3c11bc6a2f fix bug of generating plural in webhook (#133)
* fix bug when generating plural in webhook

* dep ensure

* remove unused comment
2018-10-22 21:02:30 -07:00
Mustafa Demirhan 6c3ae54dda Add reconciler metrics (#127)
* Add reconciler metrics for queue depth, reconcile count & reconcile latency.

* Update deps.

* Change queue depth measurement type to int64 from float64

* Address PR comments

* Add extra unit tests.

* Minor fixes.

* Address PR comments by adding extra documentation

* Add tests for testing/fake_stats_reporter

* Addressed PR comments.

* Address PR comments.
2018-10-22 14:34:30 -07:00
jonjohnsonjr c1fcae7b28 Allow unknown JSON fields (#129)
This enables us to make additive changes without breaking downgrades.

Unfortunate side effect is that we don't get a nice typo checker in the
webhook :(
2018-10-21 06:23:29 -07:00
Ivan Mikushin 62bcfe912f Prepare for global resync on ConfigMap changes (#132)
* Prepare for global resync on ConfigMap changes

- Add GlobalResync(cache.SharedInformer) method to *controller.Impl
- Move UntypedStore from serving/pkg/config to pkg/configmap
- Add onAfterStore callbacks to UntypedStore
- Add TypeFilter to enable composable construction of such callbacks

* Address review

- Unit test GlobalResync()
- Reimpl GlobalResync() using ListKeys()

* Update comments

* Add test for onAfterStore

* Update godoc comment for Logger
2018-10-18 09:47:28 -07:00
Markus Thömmes 403c2256ff Add timeKey so time is actually logged in e2e tests. (#122)
* Add timeKey so time is actually logged in e2e tests.

* Correct mistake.
2018-10-15 09:06:27 -07:00
Markus Thömmes 77041f6b66 Support 'hostname' and 'ip' when communicating with ingressgateway. (#118) 2018-10-11 19:03:26 -07:00
Zrss 2b0d4fc1cc Prints requestheader-client-ca-file instead of ca.crt (#123) 2018-10-11 07:24:26 -07:00
srinivashegde86 bb9898e8eb Move duration as an arg for WaitForDeploymentState (#113) 2018-10-10 10:04:27 -07:00
Mustafa Demirhan e9a1a3e8c2 Add timestamps to the e2e logs. (#121) 2018-10-09 14:02:26 -07:00
Vincent Demeester ba1a828cd5 Bump k8s dep to 1.11.3 (#120)
Signed-off-by: Vincent Demeester <vdemeest@redhat.com>
2018-10-09 07:57:26 -07:00
Matt Moore 1a50a39daf Add Generation variants of kmeta/labels.go (#117)
Unlike `ResourceVersion`, which changes whenever the resource changes at all (including `/status` which can be high churn), `Generation` only changes when the `/spec` of a CRD changes (for CRDs starting in 1.11, right now they are locked at `generation: 1`).

These methods are useful for interacting with K8s resource now, and will be useful for CRDs soon.

Fixes: https://github.com/knative/pkg/issues/116
2018-10-08 02:14:25 -07:00
Matt Moore 1f153817b2 Extend the resync period for `configmap`. (#115)
Fixes: https://github.com/knative/pkg/issues/114
2018-10-07 04:26:25 -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
Scott Nichols f1c87f1e08 Updating to k8s.1.11.2 (#111) 2018-10-02 20:42:23 -07:00
Christie Wilson 49f84a651e Move docs from knative/serving to knative/pkg (#102)
* Move docs from knative/serving to knative/pkg

While working on knative/build-pipeline#16
I started trying to build some integration tests, and I wanted to use
the code which had been moved to knative/pkg, but it turned out the docs
hadn't been ported with the code, so I am moving the docs relevant to
knative/pkg/test to that repo.

Removing docs from knative/serving in https://github.com/knative/serving/pull/2097.

* Fix knative/serving specific docs

Fixed copy-pasted references to `knative/serving/test` which should be
`knative/pkg/test`.

Fixed examples which were specific to `knative/serving`; in the case of
the command arg examples, removed the parts which are specific to those
e2e tests (though this would make them harder to use by copy and paste,
but since the libs are in a common repo now anyway that's probably
okay).

Tried to make the metric legend easier to read.
2018-10-02 15:20:23 -07:00
Vincent Demeester 8e471c3d74 Use `/usr/bin/env bash` instead of `/bin/bash` (#107)
Some systems may not have `/bin/bash` (NixOS for example)… Using
`/usr/bin/env bash` has the benefit of looking for whatever the
default version of the program is in your current environment.

Signed-off-by: Vincent Demeester <vdemeest@redhat.com>
2018-10-02 00:02:23 -07:00
Vincent Demeester d1e9b4ca17 Bump spf13/flag to 1.0.2 (#108)
Signed-off-by: Vincent Demeester <vdemeest@redhat.com>
2018-10-01 23:23:23 -07:00
Ivan Mikushin f00975a13e Tracker: delete objRef's keyset when it is no longer needed (#110) 2018-10-01 17:10:23 -07:00
Adriano Cunha 013d262286 Update knative/test-infra (#109)
Major changes:
* fixes and updates to E2E test framework
* better parsing of E2E test results
2018-10-01 12:19:23 -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
Stephen L 5c591c0518 exclude /test/... for code coverage calculation & report (#101)
https://github.com/knative/test-infra/issues/153
2018-09-27 15:28:21 -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
Matt Moore e653ef4b1b This change implements a more generalized form of the BuildTracker. (#95)
To use this with a typical informer, e.g. the way `Route` would monitor `Configurations` and `Revisions`, you'd do something like:
```go
	c := &Reconciler{
		Base:                 reconciler.NewBase(opt, controllerAgentName),
		...
	}
	impl := controller.NewImpl(c, c.Logger, "Routes")

        t := New(impl.EnqueueKey, 30*time.Minute)
        configInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
                AddFunc:    t.OnChanged,
                UpdateFunc: controller.PassNew(t.OnChanged),
        })
        revisionInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
                AddFunc:    t.OnChanged,
                UpdateFunc: controller.PassNew(t.OnChanged),
        })

        // Now use c.tracker.Track(revisionRef, route) or c.tracker.Track(configRef, route)
        // each Reconcile(route) to refresh the cross-object leases.
        c.tracker = t
```

To use this with a `duck.InformerFactory`, e.g. the way `Revision` will monitor `BuildRef`s you'd do something like:
```go
	c := &Reconciler{
		Base:             reconciler.NewBase(opt, controllerAgentName),
		...
	}
	impl := controller.NewImpl(c, c.Logger, "Revisions")

        t := New(impl.EnqueueKey, 30*time.Minute)
        cif := &duck.CachedInformerFactory{
                Delegate: &duck.EnqueueInformerFactory{
                        Delegate: buildInformerFactory,
                        EventHandler: cache.ResourceEventHandlerFuncs{
                                AddFunc:    t.OnChanged,
                                UpdateFunc: controller.PassNew(t.OnChanged),
                        },
                },
        }

        // Now use: `c.buildInformerFactory.Get()` to access ObjectReferences.
        c.buildInformerFactory = buildInformerFactory

        // Now use: `c.tracker.Track(rev.Spec.BuildRef, rev)` to queue `rev`
        // each time `rev.Spec.BuildRef` changes (expires 30 minutes after BuildRef
        // points to something else).
        c.tracker = t
```

Fixes: https://github.com/knative/pkg/issues/94
2018-09-26 17:31:21 -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 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