Skip to content

Commit 1592b5e

Browse files
authored
Merge pull request #596 from kubernetes-sigs/master
🏃 Release v0.2.1
2 parents e1159d6 + 6993406 commit 1592b5e

File tree

7 files changed

+191
-23
lines changed

7 files changed

+191
-23
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/gogo/protobuf v1.1.1 // indirect
1212
github.com/golang/groupcache v0.0.0-20180513044358-24b0969c4cb7 // indirect
1313
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf // indirect
14-
github.com/googleapis/gnostic v0.2.0 // indirect
14+
github.com/googleapis/gnostic v0.3.1 // indirect
1515
github.com/hashicorp/golang-lru v0.0.0-20180201235237-0fb14efe8c47 // indirect
1616
github.com/imdario/mergo v0.3.6 // indirect
1717
github.com/json-iterator/go v1.1.5 // indirect

go.sum

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
55
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
66
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
77
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
8+
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
89
github.com/evanphx/json-patch v4.5.0+incompatible h1:ouOWdg56aJriqS0huScTkVXPC5IcNrDCXZ6OoTAWu7M=
910
github.com/evanphx/json-patch v4.5.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
1011
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
@@ -19,10 +20,14 @@ github.com/golang/groupcache v0.0.0-20180513044358-24b0969c4cb7 h1:u4bArs140e9+A
1920
github.com/golang/groupcache v0.0.0-20180513044358-24b0969c4cb7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
2021
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
2122
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
23+
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
24+
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
2225
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf h1:+RRA9JqSOZFfKrOeqr2z77+8R2RKyh8PG66dcu1V0ck=
2326
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
2427
github.com/googleapis/gnostic v0.2.0 h1:l6N3VoaVzTncYYW+9yOz2LJJammFZGBO13sqgEhpy9g=
2528
github.com/googleapis/gnostic v0.2.0/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
29+
github.com/googleapis/gnostic v0.3.1 h1:WeAefnSUHlBb0iJKwxFDZdbfGwkd7xRNuV+IpXMJhYk=
30+
github.com/googleapis/gnostic v0.3.1/go.mod h1:on+2t9HRStVgn95RSsFWFz+6Q0Snyqv1awfrALZdbtU=
2631
github.com/hashicorp/golang-lru v0.0.0-20180201235237-0fb14efe8c47 h1:UnszMmmmm5vLwWzDjTFVIkfhvWF1NdrmChl8L2NUDCw=
2732
github.com/hashicorp/golang-lru v0.0.0-20180201235237-0fb14efe8c47/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
2833
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
@@ -102,6 +107,8 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkep
102107
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
103108
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
104109
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
110+
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
111+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
105112
k8s.io/api v0.0.0-20190409021203-6e4e0e4f393b h1:aBGgKJUM9Hk/3AE8WaZIApnTxG35kbuQba2w+SXqezo=
106113
k8s.io/api v0.0.0-20190409021203-6e4e0e4f393b/go.mod h1:iuAfoD4hCxJ8Onx9kaTIt30j7jUFS00AXQi6QMi99vA=
107114
k8s.io/apiextensions-apiserver v0.0.0-20190409022649-727a075fdec8 h1:q1Qvjzs/iEdXF6A1a8H3AKVFDzJNcJn3nXMs6R6qFtA=

hack/ci-check-everything.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2018 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -e
18+
19+
export GO111MODULE=on
20+
export TRACE=1
21+
22+
# Not included or existing by default in Prow
23+
export PATH=$(go env GOPATH)/bin:$PATH
24+
mkdir -p $(go env GOPATH)/bin
25+
26+
echo "Installing dep"
27+
export DEP_RELEASE_TAG=v0.5.4
28+
curl --location --silent --retry 5 --fail https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
29+
echo "Finished installing dep"
30+
31+
echo "Installing golangci-lint"
32+
curl --location --silent --retry 5 --fail https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.15.0
33+
echo "Finished installing golangci-lint"
34+
35+
$(dirname ${BASH_SOURCE})/check-everything.sh

pkg/client/options.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,21 @@ func (m MatchingLabels) ApplyToDeleteAllOf(opts *DeleteAllOfOptions) {
313313
m.ApplyToList(&opts.ListOptions)
314314
}
315315

316+
// MatchingLabelsSelector filters the list/delete operation on the given label
317+
// selector (or index in the case of cached lists). A struct is used because
318+
// labels.Selector is an interface, which cannot be aliased.
319+
type MatchingLabelsSelector struct {
320+
labels.Selector
321+
}
322+
323+
func (m MatchingLabelsSelector) ApplyToList(opts *ListOptions) {
324+
opts.LabelSelector = m
325+
}
326+
327+
func (m MatchingLabelsSelector) ApplyToDeleteAllOf(opts *DeleteAllOfOptions) {
328+
m.ApplyToList(&opts.ListOptions)
329+
}
330+
316331
// MatchingField filters the list operation on the given field selector
317332
// (or index in the case of cached lists).
318333
//
@@ -321,7 +336,7 @@ func MatchingField(name, val string) MatchingFields {
321336
return MatchingFields{name: val}
322337
}
323338

324-
// MatchingField filters the list/delete operation on the given field selector
339+
// MatchingField filters the list/delete operation on the given field Set
325340
// (or index in the case of cached lists).
326341
type MatchingFields fields.Set
327342

@@ -335,6 +350,21 @@ func (m MatchingFields) ApplyToDeleteAllOf(opts *DeleteAllOfOptions) {
335350
m.ApplyToList(&opts.ListOptions)
336351
}
337352

353+
// MatchingFieldsSelector filters the list/delete operation on the given field
354+
// selector (or index in the case of cached lists). A struct is used because
355+
// fields.Selector is an interface, which cannot be aliased.
356+
type MatchingFieldsSelector struct {
357+
fields.Selector
358+
}
359+
360+
func (m MatchingFieldsSelector) ApplyToList(opts *ListOptions) {
361+
opts.FieldSelector = m
362+
}
363+
364+
func (m MatchingFieldsSelector) ApplyToDeleteAllOf(opts *DeleteAllOfOptions) {
365+
m.ApplyToList(&opts.ListOptions)
366+
}
367+
338368
// InNamespace restricts the list/delete operation to the given namespace.
339369
type InNamespace string
340370

pkg/doc.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ Usage
148148
The following example shows creating a new Controller program which Reconciles ReplicaSet objects in response
149149
to Pod or ReplicaSet events. The Reconciler function simply adds a label to the ReplicaSet.
150150
151-
See the example/main.go for a usage example.
151+
See the examples/builtins/main.go for a usage example.
152152
153153
Controller Example
154154
@@ -159,7 +159,7 @@ Controller Example
159159
1.2 Pod (created by ReplicaSet) -> handler.EnqueueRequestForOwnerHandler - enqueue a Request with the
160160
Owning ReplicaSet Namespace and Name.
161161
162-
2. reconcile ReplicaSet in response to an event
162+
2. Reconcile ReplicaSet in response to an event
163163
164164
2.1 ReplicaSet object created -> Read ReplicaSet, try to read Pods -> if is missing create Pods.
165165
@@ -171,7 +171,7 @@ Watching and EventHandling
171171
172172
Controllers may Watch multiple Kinds of objects (e.g. Pods, ReplicaSets and Deployments), but they reconcile
173173
only a single Type. When one Type of object must be updated in response to changes in another Type of object,
174-
an EnqueueRequestFromMapFunc may be used to map events from one type to another. e.g. Respond to a cluster resize
174+
an EnqueueRequestsFromMapFunc may be used to map events from one type to another. e.g. Respond to a cluster resize
175175
event (add / delete Node) by re-reconciling all instances of some API.
176176
177177
A Deployment Controller might use an EnqueueRequestForObject and EnqueueRequestForOwner to:

pkg/handler/eventhandler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
// * Use EnqueueRequestForOwner to reconcile the owner of the object the event is for
3434
// - do this for events for the types the Controller creates. (e.g. ReplicaSets created by a Deployment Controller)
3535
//
36-
// * Use EnqueueRequestFromMapFunc to transform an event for an object to a reconcile of an object
36+
// * Use EnqueueRequestsFromMapFunc to transform an event for an object to a reconcile of an object
3737
// of a different type - do this for events for types the Controller may be interested in, but doesn't create.
3838
// (e.g. If Foo responds to cluster size events, map Node events to Foo objects.)
3939
//

pkg/log/zap/zap.go

Lines changed: 113 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,45 +29,141 @@ import (
2929
"go.uber.org/zap/zapcore"
3030
)
3131

32+
// New returns a brand new Logger configured with Opts. It
33+
// uses KubeAwareEncoder which adds Type information and
34+
// Namespace/Name to the log.
35+
func New(opts ...Opts) logr.Logger {
36+
return zapr.NewLogger(NewRaw(opts...))
37+
}
38+
3239
// Logger is a Logger implementation.
3340
// If development is true, a Zap development config will be used
3441
// (stacktraces on warnings, no sampling), otherwise a Zap production
3542
// config will be used (stacktraces on errors, sampling).
43+
//
44+
// Deprecated, use New() and the functional opts pattern instead:
45+
//
46+
// New(func(o *Options){
47+
// o.Development: development,
48+
// })
3649
func Logger(development bool) logr.Logger {
3750
return LoggerTo(os.Stderr, development)
3851
}
3952

4053
// LoggerTo returns a new Logger implementation using Zap which logs
4154
// to the given destination, instead of stderr. It otherwise behaves like
4255
// ZapLogger.
56+
//
57+
// Deprecated, use New() and the functional opts pattern instead:
58+
//
59+
// New(func(o *Options){
60+
// o.Development: development,
61+
// o.DestWriter: writer,
62+
// })
4363
func LoggerTo(destWriter io.Writer, development bool) logr.Logger {
4464
return zapr.NewLogger(RawLoggerTo(destWriter, development))
4565
}
4666

4767
// RawLoggerTo returns a new zap.Logger configured with KubeAwareEncoder
4868
// which logs to a given destination
69+
//
70+
// Deprecated, use NewRaw() and the functional opts pattern instead:
71+
//
72+
// NewRaw(func(o *Options){
73+
// o.Development: development,
74+
// })
4975
func RawLoggerTo(destWriter io.Writer, development bool, opts ...zap.Option) *zap.Logger {
50-
// this basically mimics New<type>Config, but with a custom sink
51-
sink := zapcore.AddSync(destWriter)
52-
53-
var enc zapcore.Encoder
54-
var lvl zap.AtomicLevel
55-
if development {
56-
encCfg := zap.NewDevelopmentEncoderConfig()
57-
enc = zapcore.NewConsoleEncoder(encCfg)
58-
lvl = zap.NewAtomicLevelAt(zap.DebugLevel)
59-
opts = append(opts, zap.Development(), zap.AddStacktrace(zap.ErrorLevel))
76+
o := func(o *Options) {
77+
o.DestWritter = destWriter
78+
o.Development = development
79+
o.ZapOpts = opts
80+
}
81+
return NewRaw(o)
82+
}
83+
84+
// Opts allows to manipulate Options
85+
type Opts func(*Options)
86+
87+
// Options contains all possible settings
88+
type Options struct {
89+
// If Development is true, a Zap development config will be used
90+
// (stacktraces on warnings, no sampling), otherwise a Zap production
91+
// config will be used (stacktraces on errors, sampling).
92+
Development bool
93+
// The encoder to use, defaults to console when Development is true
94+
// and JSON otherwise
95+
Encoder zapcore.Encoder
96+
// The destination to write to, defaults to os.Stderr
97+
DestWritter io.Writer
98+
// The level to use, defaults to Debug when Development is true and
99+
// Info otherwise
100+
Level *zap.AtomicLevel
101+
// StacktraceLevel is the level at and above which stacktraces will
102+
// be recorded for all messages. Defaults to Warn when Development
103+
// is true and Error otherwise
104+
StacktraceLevel *zap.AtomicLevel
105+
// Raw zap.Options to configure on the underlying zap logger
106+
ZapOpts []zap.Option
107+
}
108+
109+
// addDefaults adds defaults to the Options
110+
func (o *Options) addDefaults() {
111+
if o.DestWritter == nil {
112+
o.DestWritter = os.Stderr
113+
}
114+
115+
if o.Development {
116+
if o.Encoder == nil {
117+
encCfg := zap.NewDevelopmentEncoderConfig()
118+
o.Encoder = zapcore.NewConsoleEncoder(encCfg)
119+
}
120+
if o.Level == nil {
121+
lvl := zap.NewAtomicLevelAt(zap.DebugLevel)
122+
o.Level = &lvl
123+
}
124+
if o.StacktraceLevel == nil {
125+
lvl := zap.NewAtomicLevelAt(zap.WarnLevel)
126+
o.StacktraceLevel = &lvl
127+
}
128+
o.ZapOpts = append(o.ZapOpts, zap.Development())
129+
60130
} else {
61-
encCfg := zap.NewProductionEncoderConfig()
62-
enc = zapcore.NewJSONEncoder(encCfg)
63-
lvl = zap.NewAtomicLevelAt(zap.InfoLevel)
64-
opts = append(opts, zap.AddStacktrace(zap.WarnLevel),
131+
if o.Encoder == nil {
132+
encCfg := zap.NewProductionEncoderConfig()
133+
o.Encoder = zapcore.NewJSONEncoder(encCfg)
134+
}
135+
if o.Level == nil {
136+
lvl := zap.NewAtomicLevelAt(zap.InfoLevel)
137+
o.Level = &lvl
138+
}
139+
if o.StacktraceLevel == nil {
140+
lvl := zap.NewAtomicLevelAt(zap.ErrorLevel)
141+
o.StacktraceLevel = &lvl
142+
}
143+
o.ZapOpts = append(o.ZapOpts,
65144
zap.WrapCore(func(core zapcore.Core) zapcore.Core {
66145
return zapcore.NewSampler(core, time.Second, 100, 100)
67146
}))
68147
}
69-
opts = append(opts, zap.AddCallerSkip(1), zap.ErrorOutput(sink))
70-
log := zap.New(zapcore.NewCore(&KubeAwareEncoder{Encoder: enc, Verbose: development}, sink, lvl))
71-
log = log.WithOptions(opts...)
148+
149+
o.ZapOpts = append(o.ZapOpts, zap.AddStacktrace(o.StacktraceLevel))
150+
}
151+
152+
// NewRaw returns a new zap.Logger configured with the passed Opts
153+
// or their defaults. It uses KubeAwareEncoder which adds Type
154+
// information and Namespace/Name to the log.
155+
func NewRaw(opts ...Opts) *zap.Logger {
156+
o := &Options{}
157+
for _, opt := range opts {
158+
opt(o)
159+
}
160+
o.addDefaults()
161+
162+
// this basically mimics New<type>Config, but with a custom sink
163+
sink := zapcore.AddSync(o.DestWritter)
164+
165+
o.ZapOpts = append(o.ZapOpts, zap.AddCallerSkip(1), zap.ErrorOutput(sink))
166+
log := zap.New(zapcore.NewCore(&KubeAwareEncoder{Encoder: o.Encoder, Verbose: o.Development}, sink, *o.Level))
167+
log = log.WithOptions(o.ZapOpts...)
72168
return log
73169
}

0 commit comments

Comments
 (0)