Skip to content

Commit 22691a0

Browse files
authored
Merge pull request #1014 from vincepri/prepare057
Prepare for v0.5.7
2 parents 3556b1e + 36711f4 commit 22691a0

File tree

8 files changed

+35
-79
lines changed

8 files changed

+35
-79
lines changed

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ require (
3131
k8s.io/utils v0.0.0-20200603063816-c1c6865ac451
3232
sigs.k8s.io/yaml v1.1.0
3333
)
34+
35+
replace github.com/evanphx/json-patch => github.com/evanphx/json-patch v0.0.0-20190815234213-e83c0a1c26c8

go.sum

Lines changed: 2 additions & 57 deletions
Large diffs are not rendered by default.

pkg/client/apiutil/apimachinery.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func GVKForObject(obj runtime.Object, scheme *runtime.Scheme) (schema.GroupVersi
5353
return schema.GroupVersionKind{}, err
5454
}
5555
if isUnversioned {
56-
return schema.GroupVersionKind{}, fmt.Errorf("cannot create a new informer for the unversioned type %T", obj)
56+
return schema.GroupVersionKind{}, fmt.Errorf("cannot create group-version-kind for unversioned type %T", obj)
5757
}
5858

5959
if len(gvks) < 1 {

pkg/controller/controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"k8s.io/client-go/util/workqueue"
2323
"sigs.k8s.io/controller-runtime/pkg/handler"
2424
"sigs.k8s.io/controller-runtime/pkg/internal/controller"
25+
"sigs.k8s.io/controller-runtime/pkg/internal/log"
2526
"sigs.k8s.io/controller-runtime/pkg/manager"
2627
"sigs.k8s.io/controller-runtime/pkg/predicate"
2728
"sigs.k8s.io/controller-runtime/pkg/ratelimiter"
@@ -99,6 +100,7 @@ func New(name string, mgr manager.Manager, options Options) (Controller, error)
99100
},
100101
MaxConcurrentReconciles: options.MaxConcurrentReconciles,
101102
Name: name,
103+
Log: log.RuntimeLog.WithName("controller").WithValues("controller", name),
102104
}
103105

104106
// Add the controller as a Manager components

pkg/internal/controller/controller.go

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"sync"
2222
"time"
2323

24+
"github.com/go-logr/logr"
2425
"k8s.io/apimachinery/pkg/runtime"
2526
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
2627
"k8s.io/apimachinery/pkg/util/wait"
@@ -29,15 +30,12 @@ import (
2930
"sigs.k8s.io/controller-runtime/pkg/client"
3031
"sigs.k8s.io/controller-runtime/pkg/handler"
3132
ctrlmetrics "sigs.k8s.io/controller-runtime/pkg/internal/controller/metrics"
32-
logf "sigs.k8s.io/controller-runtime/pkg/internal/log"
3333
"sigs.k8s.io/controller-runtime/pkg/predicate"
3434
"sigs.k8s.io/controller-runtime/pkg/reconcile"
3535
"sigs.k8s.io/controller-runtime/pkg/runtime/inject"
3636
"sigs.k8s.io/controller-runtime/pkg/source"
3737
)
3838

39-
var log = logf.RuntimeLog.WithName("controller")
40-
4139
var _ inject.Injector = &Controller{}
4240

4341
// Controller implements controller.Controller
@@ -88,6 +86,9 @@ type Controller struct {
8886

8987
// watches maintains a list of sources, handlers, and predicates to start when the controller is started.
9088
watches []watchDescription
89+
90+
// Log is used to log messages to users during reconciliation, or for example when a watch is started.
91+
Log logr.Logger
9192
}
9293

9394
// watchDescription contains all the information necessary to start a watch.
@@ -122,7 +123,7 @@ func (c *Controller) Watch(src source.Source, evthdler handler.EventHandler, prc
122123

123124
c.watches = append(c.watches, watchDescription{src: src, handler: evthdler, predicates: prct})
124125
if c.Started {
125-
log.Info("Starting EventSource", "controller", c.Name, "source", src)
126+
c.Log.Info("Starting EventSource", "source", src)
126127
return src.Start(evthdler, c.Queue, prct...)
127128
}
128129

@@ -148,14 +149,14 @@ func (c *Controller) Start(stop <-chan struct{}) error {
148149
// caches to sync so that they have a chance to register their intendeded
149150
// caches.
150151
for _, watch := range c.watches {
151-
log.Info("Starting EventSource", "controller", c.Name, "source", watch.src)
152+
c.Log.Info("Starting EventSource", "source", watch.src)
152153
if err := watch.src.Start(watch.handler, c.Queue, watch.predicates...); err != nil {
153154
return err
154155
}
155156
}
156157

157158
// Start the SharedIndexInformer factories to begin populating the SharedIndexInformer caches
158-
log.Info("Starting Controller", "controller", c.Name)
159+
c.Log.Info("Starting Controller")
159160

160161
for _, watch := range c.watches {
161162
syncingSource, ok := watch.src.(source.SyncingSource)
@@ -166,7 +167,7 @@ func (c *Controller) Start(stop <-chan struct{}) error {
166167
// This code is unreachable in case of kube watches since WaitForCacheSync will never return an error
167168
// Leaving it here because that could happen in the future
168169
err := fmt.Errorf("failed to wait for %s caches to sync: %w", c.Name, err)
169-
log.Error(err, "Could not wait for Cache to sync", "controller", c.Name)
170+
c.Log.Error(err, "Could not wait for Cache to sync")
170171
return err
171172
}
172173
}
@@ -176,7 +177,7 @@ func (c *Controller) Start(stop <-chan struct{}) error {
176177
}
177178

178179
// Launch workers to process resources
179-
log.Info("Starting workers", "controller", c.Name, "worker count", c.MaxConcurrentReconciles)
180+
c.Log.Info("Starting workers", "worker count", c.MaxConcurrentReconciles)
180181
for i := 0; i < c.MaxConcurrentReconciles; i++ {
181182
// Process work items
182183
go wait.Until(c.worker, c.JitterPeriod, stop)
@@ -190,7 +191,7 @@ func (c *Controller) Start(stop <-chan struct{}) error {
190191
}
191192

192193
<-stop
193-
log.Info("Stopping workers", "controller", c.Name)
194+
c.Log.Info("Stopping workers")
194195
return nil
195196
}
196197

@@ -228,23 +229,23 @@ func (c *Controller) reconcileHandler(obj interface{}) bool {
228229
c.updateMetrics(time.Since(reconcileStartTS))
229230
}()
230231

231-
var req reconcile.Request
232-
var ok bool
233-
if req, ok = obj.(reconcile.Request); !ok {
232+
// Make sure that the the object is a valid request.
233+
req, ok := obj.(reconcile.Request)
234+
if !ok {
234235
// As the item in the workqueue is actually invalid, we call
235236
// Forget here else we'd go into a loop of attempting to
236237
// process a work item that is invalid.
237238
c.Queue.Forget(obj)
238-
log.Error(nil, "Queue item was not a Request",
239-
"controller", c.Name, "type", fmt.Sprintf("%T", obj), "value", obj)
239+
c.Log.Error(nil, "Queue item was not a Request", "type", fmt.Sprintf("%T", obj), "value", obj)
240240
// Return true, don't take a break
241241
return true
242242
}
243+
243244
// RunInformersAndControllers the syncHandler, passing it the namespace/Name string of the
244245
// resource to be synced.
245246
if result, err := c.Do.Reconcile(req); err != nil {
246247
c.Queue.AddRateLimited(req)
247-
log.Error(err, "Reconciler error", "controller", c.Name, "request", req)
248+
c.Log.Error(err, "Reconciler error", "name", req.Name, "namespace", req.Namespace)
248249
ctrlmetrics.ReconcileErrors.WithLabelValues(c.Name).Inc()
249250
ctrlmetrics.ReconcileTotal.WithLabelValues(c.Name, "error").Inc()
250251
return false
@@ -268,7 +269,7 @@ func (c *Controller) reconcileHandler(obj interface{}) bool {
268269
c.Queue.Forget(obj)
269270

270271
// TODO(directxman12): What does 1 mean? Do we want level constants? Do we want levels at all?
271-
log.V(1).Info("Successfully Reconciled", "controller", c.Name, "request", req)
272+
c.Log.V(1).Info("Successfully Reconciled", "name", req.Name, "namespace", req.Namespace)
272273

273274
ctrlmetrics.ReconcileTotal.WithLabelValues(c.Name, "success").Inc()
274275
// Return true, don't take a break

pkg/internal/controller/controller_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"sigs.k8s.io/controller-runtime/pkg/controller/controllertest"
3535
"sigs.k8s.io/controller-runtime/pkg/handler"
3636
ctrlmetrics "sigs.k8s.io/controller-runtime/pkg/internal/controller/metrics"
37+
"sigs.k8s.io/controller-runtime/pkg/internal/log"
3738
"sigs.k8s.io/controller-runtime/pkg/predicate"
3839
"sigs.k8s.io/controller-runtime/pkg/reconcile"
3940
"sigs.k8s.io/controller-runtime/pkg/source"
@@ -65,6 +66,7 @@ var _ = Describe("controller", func() {
6566
MaxConcurrentReconciles: 1,
6667
Do: fakeReconcile,
6768
MakeQueue: func() workqueue.RateLimitingInterface { return queue },
69+
Log: log.RuntimeLog.WithName("controller").WithName("test"),
6870
}
6971
Expect(ctrl.InjectFunc(func(interface{}) error { return nil })).To(Succeed())
7072
})

pkg/internal/testing/integration/control_plane.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"net/url"
66

77
"k8s.io/apimachinery/pkg/runtime/serializer"
8+
utilerrors "k8s.io/apimachinery/pkg/util/errors"
89
"k8s.io/client-go/kubernetes/scheme"
910
"k8s.io/client-go/rest"
1011

@@ -42,17 +43,20 @@ func (f *ControlPlane) Start() error {
4243

4344
// Stop will stop your control plane processes, and clean up their data.
4445
func (f *ControlPlane) Stop() error {
46+
var errList []error
47+
4548
if f.APIServer != nil {
4649
if err := f.APIServer.Stop(); err != nil {
47-
return err
50+
errList = append(errList, err)
4851
}
4952
}
5053
if f.Etcd != nil {
5154
if err := f.Etcd.Stop(); err != nil {
52-
return err
55+
errList = append(errList, err)
5356
}
5457
}
55-
return nil
58+
59+
return utilerrors.NewAggregate(errList)
5660
}
5761

5862
// APIURL returns the URL you should connect to to talk to your API.

pkg/runtime/inject/inject.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type Cache interface {
3333
}
3434

3535
// CacheInto will set informers on i and return the result if it implements Cache. Returns
36-
//// false if i does not implement Cache.
36+
// false if i does not implement Cache.
3737
func CacheInto(c cache.Cache, i interface{}) (bool, error) {
3838
if s, ok := i.(Cache); ok {
3939
return true, s.InjectCache(c)
@@ -62,7 +62,7 @@ type Config interface {
6262
}
6363

6464
// ConfigInto will set config on i and return the result if it implements Config. Returns
65-
//// false if i does not implement Config.
65+
// false if i does not implement Config.
6666
func ConfigInto(config *rest.Config, i interface{}) (bool, error) {
6767
if s, ok := i.(Config); ok {
6868
return true, s.InjectConfig(config)

0 commit comments

Comments
 (0)