From c6589325d42fb38b1d91ee1fe525c57bd0534522 Mon Sep 17 00:00:00 2001 From: xrmzju Date: Mon, 19 Aug 2019 16:19:43 +0800 Subject: [PATCH 01/10] should support webhook certDir args --- pkg/manager/internal.go | 9 +++++++-- pkg/manager/manager.go | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/manager/internal.go b/pkg/manager/internal.go index ed4ae806e3..5e5a2611e0 100644 --- a/pkg/manager/internal.go +++ b/pkg/manager/internal.go @@ -111,6 +111,10 @@ type controllerManager struct { port int // host is the hostname that the webhook server binds to. host string + // CertDir is the directory that contains the server key and certificate. + // if not set, webhook server would look up the server key and certificate in + // {TempDir}/k8s-webhook-server/serving-certs + certDir string webhookServer *webhook.Server @@ -219,8 +223,9 @@ func (cm *controllerManager) GetAPIReader() client.Reader { func (cm *controllerManager) GetWebhookServer() *webhook.Server { if cm.webhookServer == nil { cm.webhookServer = &webhook.Server{ - Port: cm.port, - Host: cm.host, + Port: cm.port, + Host: cm.host, + CertDir: cm.certDir, } if err := cm.Add(cm.webhookServer); err != nil { panic("unable to add webhookServer to the controller manager") diff --git a/pkg/manager/manager.go b/pkg/manager/manager.go index 56a34cba6e..222ab4f4fa 100644 --- a/pkg/manager/manager.go +++ b/pkg/manager/manager.go @@ -149,6 +149,10 @@ type Options struct { // It is used to set webhook.Server.Host. Host string + // CertDir is the directory that contains the server key and certificate. + // if not set, webhook server would look up the server key and certificate in + // {TempDir}/k8s-webhook-server/serving-certs + CertDir string // Functions to all for a user to customize the values that will be injected. // NewCache is the function that will create the cache to be used @@ -271,6 +275,7 @@ func New(config *rest.Config, options Options) (Manager, error) { internalStopper: stop, port: options.Port, host: options.Host, + certDir: options.CertDir, leaseDuration: *options.LeaseDuration, renewDeadline: *options.RenewDeadline, retryPeriod: *options.RetryPeriod, From 6b4e5deaed580baecee553677b571ef275fdc8ab Mon Sep 17 00:00:00 2001 From: Alvaro Aleman Date: Sun, 8 Sep 2019 19:08:52 +0200 Subject: [PATCH 02/10] :sparkles: Allow using ListOptions as ListOption --- pkg/client/options.go | 18 +++++++++++ pkg/client/options_test.go | 62 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 pkg/client/options_test.go diff --git a/pkg/client/options.go b/pkg/client/options.go index 4007a67657..60aa7f02b6 100644 --- a/pkg/client/options.go +++ b/pkg/client/options.go @@ -273,6 +273,24 @@ type ListOptions struct { Raw *metav1.ListOptions } +var _ ListOption = &ListOptions{} + +// ApplyToList implements ListOption for ListOptions +func (o *ListOptions) ApplyToList(lo *ListOptions) { + if o.LabelSelector != nil { + lo.LabelSelector = o.LabelSelector + } + if o.FieldSelector != nil { + lo.FieldSelector = o.FieldSelector + } + if o.Namespace != "" { + lo.Namespace = o.Namespace + } + if o.Raw != nil { + lo.Raw = o.Raw + } +} + // AsListOptions returns these options as a flattened metav1.ListOptions. // This may mutate the Raw field. func (o *ListOptions) AsListOptions() *metav1.ListOptions { diff --git a/pkg/client/options_test.go b/pkg/client/options_test.go new file mode 100644 index 0000000000..0a9be79f87 --- /dev/null +++ b/pkg/client/options_test.go @@ -0,0 +1,62 @@ +/* +Copyright 2018 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package client_test + +import ( + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/fields" + "k8s.io/apimachinery/pkg/labels" + "sigs.k8s.io/controller-runtime/pkg/client" +) + +var _ = Describe("ListOptions", func() { + It("Should set LabelSelector", func() { + labelSelector, err := labels.Parse("a=b") + Expect(err).NotTo(HaveOccurred()) + o := &client.ListOptions{LabelSelector: labelSelector} + newListOpts := &client.ListOptions{} + o.ApplyToList(newListOpts) + Expect(newListOpts).To(Equal(o)) + }) + It("Should set FieldSelector", func() { + o := &client.ListOptions{FieldSelector: fields.Nothing()} + newListOpts := &client.ListOptions{} + o.ApplyToList(newListOpts) + Expect(newListOpts).To(Equal(o)) + }) + It("Should set Namespace", func() { + o := &client.ListOptions{Namespace: "my-ns"} + newListOpts := &client.ListOptions{} + o.ApplyToList(newListOpts) + Expect(newListOpts).To(Equal(o)) + }) + It("Should set Raw", func() { + o := &client.ListOptions{Raw: &metav1.ListOptions{FieldSelector: "Hans"}} + newListOpts := &client.ListOptions{} + o.ApplyToList(newListOpts) + Expect(newListOpts).To(Equal(o)) + }) + It("Should not set anything", func() { + o := &client.ListOptions{} + newListOpts := &client.ListOptions{} + o.ApplyToList(newListOpts) + Expect(newListOpts).To(Equal(o)) + }) +}) From 05495c32537c7f998211a221bae8de65108cc718 Mon Sep 17 00:00:00 2001 From: Alvaro Aleman Date: Mon, 9 Sep 2019 18:39:33 +0200 Subject: [PATCH 03/10] :sparkles: CreateOptions implement CreateOption --- pkg/client/options.go | 15 +++++++++++++++ pkg/client/options_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/pkg/client/options.go b/pkg/client/options.go index 60aa7f02b6..2b2f9d8342 100644 --- a/pkg/client/options.go +++ b/pkg/client/options.go @@ -142,6 +142,21 @@ func (o *CreateOptions) ApplyOptions(opts []CreateOption) *CreateOptions { return o } +// ApplyToCreate implements CreateOption +func (o *CreateOptions) ApplyToCreate(co *CreateOptions) { + if o.DryRun != nil { + co.DryRun = o.DryRun + } + if o.FieldManager != "" { + co.FieldManager = o.FieldManager + } + if o.Raw != nil { + co.Raw = o.Raw + } +} + +var _ CreateOption = &CreateOptions{} + // CreateDryRunAll sets the "dry run" option to "all". // // Deprecated: Use DryRunAll diff --git a/pkg/client/options_test.go b/pkg/client/options_test.go index 0a9be79f87..9c7f26136c 100644 --- a/pkg/client/options_test.go +++ b/pkg/client/options_test.go @@ -60,3 +60,30 @@ var _ = Describe("ListOptions", func() { Expect(newListOpts).To(Equal(o)) }) }) + +var _ = Describe("CreateOptions", func() { + It("Should set DryRun", func() { + o := &client.CreateOptions{DryRun: []string{"Hello", "Theodore"}} + newCreatOpts := &client.CreateOptions{} + o.ApplyToCreate(newCreatOpts) + Expect(newCreatOpts).To(Equal(o)) + }) + It("Should set FieldManager", func() { + o := &client.CreateOptions{FieldManager: "FieldManager"} + newCreatOpts := &client.CreateOptions{} + o.ApplyToCreate(newCreatOpts) + Expect(newCreatOpts).To(Equal(o)) + }) + It("Should set Raw", func() { + o := &client.CreateOptions{Raw: &metav1.CreateOptions{DryRun: []string{"Bye", "Theodore"}}} + newCreatOpts := &client.CreateOptions{} + o.ApplyToCreate(newCreatOpts) + Expect(newCreatOpts).To(Equal(o)) + }) + It("Should not set anything", func() { + o := &client.CreateOptions{} + newCreatOpts := &client.CreateOptions{} + o.ApplyToCreate(newCreatOpts) + Expect(newCreatOpts).To(Equal(o)) + }) +}) From b11bb8967d11ec439b9e768742eacfbbebf530db Mon Sep 17 00:00:00 2001 From: Alvaro Aleman Date: Mon, 9 Sep 2019 18:51:46 +0200 Subject: [PATCH 04/10] :sparkles: DeleteOptions implements DeleteOption --- Gopkg.lock | 4 +++- pkg/client/options.go | 21 +++++++++++++++++++ pkg/client/options_test.go | 41 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/Gopkg.lock b/Gopkg.lock index 0996047409..d3d1f1dc80 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -878,11 +878,12 @@ [[projects]] branch = "master" - digest = "1:14e8a3b53e6d8cb5f44783056b71bb2ca1ac7e333939cc97f3e50b579c920845" + digest = "1:ee6063c66a2b3be97487a8df6f359cd5f38b3a0d1fc2442b49f214f24622d321" name = "k8s.io/utils" packages = [ "buffer", "integer", + "pointer", "trace", ] pruneopts = "UT" @@ -978,6 +979,7 @@ "k8s.io/client-go/tools/reference", "k8s.io/client-go/util/workqueue", "k8s.io/kube-openapi/pkg/common", + "k8s.io/utils/pointer", "sigs.k8s.io/testing_frameworks/integration", "sigs.k8s.io/testing_frameworks/integration/addr", "sigs.k8s.io/yaml", diff --git a/pkg/client/options.go b/pkg/client/options.go index 2b2f9d8342..d32b6b0345 100644 --- a/pkg/client/options.go +++ b/pkg/client/options.go @@ -226,6 +226,27 @@ func (o *DeleteOptions) ApplyOptions(opts []DeleteOption) *DeleteOptions { return o } +var _ DeleteOption = &DeleteOptions{} + +// ApplyToDelete implements DeleteOption +func (o *DeleteOptions) ApplyToDelete(do *DeleteOptions) { + if o.GracePeriodSeconds != nil { + do.GracePeriodSeconds = o.GracePeriodSeconds + } + if o.Preconditions != nil { + do.Preconditions = o.Preconditions + } + if o.PropagationPolicy != nil { + do.PropagationPolicy = o.PropagationPolicy + } + if o.Raw != nil { + do.Raw = o.Raw + } + if o.DryRun != nil { + do.DryRun = o.DryRun + } +} + // GracePeriodSeconds sets the grace period for the deletion // to the given number of seconds. type GracePeriodSeconds int64 diff --git a/pkg/client/options_test.go b/pkg/client/options_test.go index 9c7f26136c..bfc1d38e2a 100644 --- a/pkg/client/options_test.go +++ b/pkg/client/options_test.go @@ -23,6 +23,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" + utilpointer "k8s.io/utils/pointer" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -87,3 +88,43 @@ var _ = Describe("CreateOptions", func() { Expect(newCreatOpts).To(Equal(o)) }) }) + +var _ = Describe("DeleteOptions", func() { + It("Should set GracePeriodSeconds", func() { + o := &client.DeleteOptions{GracePeriodSeconds: utilpointer.Int64Ptr(42)} + newDeleteOpts := &client.DeleteOptions{} + o.ApplyToDelete(newDeleteOpts) + Expect(newDeleteOpts).To(Equal(o)) + }) + It("Should set Preconditions", func() { + o := &client.DeleteOptions{Preconditions: &metav1.Preconditions{}} + newDeleteOpts := &client.DeleteOptions{} + o.ApplyToDelete(newDeleteOpts) + Expect(newDeleteOpts).To(Equal(o)) + }) + It("Should set PropagationPolicy", func() { + policy := metav1.DeletePropagationBackground + o := &client.DeleteOptions{PropagationPolicy: &policy} + newDeleteOpts := &client.DeleteOptions{} + o.ApplyToDelete(newDeleteOpts) + Expect(newDeleteOpts).To(Equal(o)) + }) + It("Should set Raw", func() { + o := &client.DeleteOptions{Raw: &metav1.DeleteOptions{}} + newDeleteOpts := &client.DeleteOptions{} + o.ApplyToDelete(newDeleteOpts) + Expect(newDeleteOpts).To(Equal(o)) + }) + It("Should set DryRun", func() { + o := &client.DeleteOptions{DryRun: []string{"Hello", "Pippa"}} + newDeleteOpts := &client.DeleteOptions{} + o.ApplyToDelete(newDeleteOpts) + Expect(newDeleteOpts).To(Equal(o)) + }) + It("Should not set anything", func() { + o := &client.DeleteOptions{} + newDeleteOpts := &client.DeleteOptions{} + o.ApplyToDelete(newDeleteOpts) + Expect(newDeleteOpts).To(Equal(o)) + }) +}) From ccdcbc778df23f0a932ff346c69187d08fd6a95f Mon Sep 17 00:00:00 2001 From: Alvaro Aleman Date: Mon, 9 Sep 2019 18:59:19 +0200 Subject: [PATCH 05/10] :sparkles: UpdateOptions implements UpdateOption --- pkg/client/options.go | 15 +++++++++++++++ pkg/client/options_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/pkg/client/options.go b/pkg/client/options.go index d32b6b0345..91e6ef9b5a 100644 --- a/pkg/client/options.go +++ b/pkg/client/options.go @@ -446,6 +446,21 @@ func (o *UpdateOptions) ApplyOptions(opts []UpdateOption) *UpdateOptions { return o } +var _ UpdateOption = &UpdateOptions{} + +// ApplyToUpdate implements UpdateOption +func (o *UpdateOptions) ApplyToUpdate(uo *UpdateOptions) { + if o.DryRun != nil { + uo.DryRun = o.DryRun + } + if o.FieldManager != "" { + uo.FieldManager = o.FieldManager + } + if o.Raw != nil { + uo.Raw = o.Raw + } +} + // UpdateDryRunAll sets the "dry run" option to "all". // // Deprecated: Use DryRunAll diff --git a/pkg/client/options_test.go b/pkg/client/options_test.go index bfc1d38e2a..cdaf9ecef8 100644 --- a/pkg/client/options_test.go +++ b/pkg/client/options_test.go @@ -128,3 +128,30 @@ var _ = Describe("DeleteOptions", func() { Expect(newDeleteOpts).To(Equal(o)) }) }) + +var _ = Describe("UpdateOptions", func() { + It("Should set DryRun", func() { + o := &client.UpdateOptions{DryRun: []string{"Bye", "Pippa"}} + newUpdateOpts := &client.UpdateOptions{} + o.ApplyToUpdate(newUpdateOpts) + Expect(newUpdateOpts).To(Equal(o)) + }) + It("Should set FieldManager", func() { + o := &client.UpdateOptions{FieldManager: "Hello Boris"} + newUpdateOpts := &client.UpdateOptions{} + o.ApplyToUpdate(newUpdateOpts) + Expect(newUpdateOpts).To(Equal(o)) + }) + It("Should set Raw", func() { + o := &client.UpdateOptions{Raw: &metav1.UpdateOptions{}} + newUpdateOpts := &client.UpdateOptions{} + o.ApplyToUpdate(newUpdateOpts) + Expect(newUpdateOpts).To(Equal(o)) + }) + It("Should not set anything", func() { + o := &client.UpdateOptions{} + newUpdateOpts := &client.UpdateOptions{} + o.ApplyToUpdate(newUpdateOpts) + Expect(newUpdateOpts).To(Equal(o)) + }) +}) From 1e8c57ffa4f8d3a41bef367e91dcecc0917be7ec Mon Sep 17 00:00:00 2001 From: Alvaro Aleman Date: Mon, 9 Sep 2019 19:07:51 +0200 Subject: [PATCH 06/10] :sparkles: PatchOptions implement PatchOpts --- pkg/client/options.go | 18 ++++++++++++++++++ pkg/client/options_test.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/pkg/client/options.go b/pkg/client/options.go index 91e6ef9b5a..e809183da7 100644 --- a/pkg/client/options.go +++ b/pkg/client/options.go @@ -518,6 +518,24 @@ func (o *PatchOptions) AsPatchOptions() *metav1.PatchOptions { return o.Raw } +var _ PatchOption = &PatchOptions{} + +// ApplyToPatch implements PatchOptions +func (o *PatchOptions) ApplyToPatch(po *PatchOptions) { + if o.DryRun != nil { + po.DryRun = o.DryRun + } + if o.Force != nil { + po.Force = o.Force + } + if o.FieldManager != "" { + po.FieldManager = o.FieldManager + } + if o.Raw != nil { + po.Raw = o.Raw + } +} + // ForceOwnership indicates that in case of conflicts with server-side apply, // the client should acquire ownership of the conflicting field. Most // controllers should use this. diff --git a/pkg/client/options_test.go b/pkg/client/options_test.go index cdaf9ecef8..2b0a69bea7 100644 --- a/pkg/client/options_test.go +++ b/pkg/client/options_test.go @@ -155,3 +155,36 @@ var _ = Describe("UpdateOptions", func() { Expect(newUpdateOpts).To(Equal(o)) }) }) + +var _ = Describe("PatchOptions", func() { + It("Should set DryRun", func() { + o := &client.PatchOptions{DryRun: []string{"Bye", "Boris"}} + newPatchOpts := &client.PatchOptions{} + o.ApplyToPatch(newPatchOpts) + Expect(newPatchOpts).To(Equal(o)) + }) + It("Should set Force", func() { + o := &client.PatchOptions{Force: utilpointer.BoolPtr(true)} + newPatchOpts := &client.PatchOptions{} + o.ApplyToPatch(newPatchOpts) + Expect(newPatchOpts).To(Equal(o)) + }) + It("Should set FieldManager", func() { + o := &client.PatchOptions{FieldManager: "Hello Julian"} + newPatchOpts := &client.PatchOptions{} + o.ApplyToPatch(newPatchOpts) + Expect(newPatchOpts).To(Equal(o)) + }) + It("Should set Raw", func() { + o := &client.PatchOptions{Raw: &metav1.PatchOptions{}} + newPatchOpts := &client.PatchOptions{} + o.ApplyToPatch(newPatchOpts) + Expect(newPatchOpts).To(Equal(o)) + }) + It("Should not set anything", func() { + o := &client.PatchOptions{} + newPatchOpts := &client.PatchOptions{} + o.ApplyToPatch(newPatchOpts) + Expect(newPatchOpts).To(Equal(o)) + }) +}) From b7dfffa247a8a194ea1b3adcec4c91475c59a786 Mon Sep 17 00:00:00 2001 From: Alvaro Aleman Date: Mon, 9 Sep 2019 19:15:41 +0200 Subject: [PATCH 07/10] :sparkles: DeleteAllOfOptions Implements DeleteAllOfOption --- pkg/client/options.go | 8 ++++++++ pkg/client/options_test.go | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/pkg/client/options.go b/pkg/client/options.go index e809183da7..961eba898b 100644 --- a/pkg/client/options.go +++ b/pkg/client/options.go @@ -575,4 +575,12 @@ func (o *DeleteAllOfOptions) ApplyOptions(opts []DeleteAllOfOption) *DeleteAllOf return o } +var _ DeleteAllOfOption = &DeleteAllOfOptions{} + +// ApplyToDeleteAllOf implements DeleteAllOfOption +func (o *DeleteAllOfOptions) ApplyToDeleteAllOf(do *DeleteAllOfOptions) { + o.ApplyToList(&do.ListOptions) + o.ApplyToDelete(&do.DeleteOptions) +} + // }}} diff --git a/pkg/client/options_test.go b/pkg/client/options_test.go index 2b0a69bea7..83b818cc5a 100644 --- a/pkg/client/options_test.go +++ b/pkg/client/options_test.go @@ -188,3 +188,18 @@ var _ = Describe("PatchOptions", func() { Expect(newPatchOpts).To(Equal(o)) }) }) + +var _ = Describe("DeleteAllOfOptions", func() { + It("Should set ListOptions", func() { + o := &client.DeleteAllOfOptions{ListOptions: client.ListOptions{Raw: &metav1.ListOptions{}}} + newDeleteAllOfOpts := &client.DeleteAllOfOptions{} + o.ApplyToDeleteAllOf(newDeleteAllOfOpts) + Expect(newDeleteAllOfOpts).To(Equal(o)) + }) + It("Should set DeleleteOptions", func() { + o := &client.DeleteAllOfOptions{DeleteOptions: client.DeleteOptions{GracePeriodSeconds: utilpointer.Int64Ptr(44)}} + newDeleteAllOfOpts := &client.DeleteAllOfOptions{} + o.ApplyToDeleteAllOf(newDeleteAllOfOpts) + Expect(newDeleteAllOfOpts).To(Equal(o)) + }) +}) From 5f7374feaed2e336e305081fae52aaf48e77fbc0 Mon Sep 17 00:00:00 2001 From: liz Date: Mon, 9 Sep 2019 12:21:23 -0400 Subject: [PATCH 08/10] Let users specify their own EventBroadcaster for the manager --- pkg/internal/recorder/recorder.go | 5 ++--- pkg/internal/recorder/recorder_test.go | 7 ++++--- pkg/manager/manager.go | 12 ++++++++++-- pkg/manager/manager_test.go | 3 ++- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/pkg/internal/recorder/recorder.go b/pkg/internal/recorder/recorder.go index 18e150594c..af230ad503 100644 --- a/pkg/internal/recorder/recorder.go +++ b/pkg/internal/recorder/recorder.go @@ -39,14 +39,13 @@ type provider struct { } // NewProvider create a new Provider instance. -func NewProvider(config *rest.Config, scheme *runtime.Scheme, logger logr.Logger) (recorder.Provider, error) { +func NewProvider(config *rest.Config, scheme *runtime.Scheme, logger logr.Logger, broadcaster record.EventBroadcaster) (recorder.Provider, error) { clientSet, err := kubernetes.NewForConfig(config) if err != nil { return nil, fmt.Errorf("failed to init clientSet: %v", err) } - p := &provider{scheme: scheme, logger: logger} - p.eventBroadcaster = record.NewBroadcaster() + p := &provider{scheme: scheme, logger: logger, eventBroadcaster: broadcaster} p.eventBroadcaster.StartRecordingToSink(&typedcorev1.EventSinkImpl{Interface: clientSet.CoreV1().Events("")}) p.eventBroadcaster.StartEventWatcher( func(e *corev1.Event) { diff --git a/pkg/internal/recorder/recorder_test.go b/pkg/internal/recorder/recorder_test.go index 35bc6f1726..8aac94a5da 100644 --- a/pkg/internal/recorder/recorder_test.go +++ b/pkg/internal/recorder/recorder_test.go @@ -21,13 +21,14 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "k8s.io/client-go/kubernetes/scheme" + "k8s.io/client-go/tools/record" "sigs.k8s.io/controller-runtime/pkg/internal/recorder" ) var _ = Describe("recorder.Provider", func() { Describe("NewProvider", func() { It("should return a provider instance and a nil error.", func() { - provider, err := recorder.NewProvider(cfg, scheme.Scheme, tlog.NullLogger{}) + provider, err := recorder.NewProvider(cfg, scheme.Scheme, tlog.NullLogger{}, record.NewBroadcaster()) Expect(provider).NotTo(BeNil()) Expect(err).NotTo(HaveOccurred()) }) @@ -36,13 +37,13 @@ var _ = Describe("recorder.Provider", func() { // Invalid the config cfg1 := *cfg cfg1.ContentType = "invalid-type" - _, err := recorder.NewProvider(&cfg1, scheme.Scheme, tlog.NullLogger{}) + _, err := recorder.NewProvider(&cfg1, scheme.Scheme, tlog.NullLogger{}, record.NewBroadcaster()) Expect(err.Error()).To(ContainSubstring("failed to init clientSet")) }) }) Describe("GetEventRecorder", func() { It("should return a recorder instance.", func() { - provider, err := recorder.NewProvider(cfg, scheme.Scheme, tlog.NullLogger{}) + provider, err := recorder.NewProvider(cfg, scheme.Scheme, tlog.NullLogger{}, record.NewBroadcaster()) Expect(err).NotTo(HaveOccurred()) recorder := provider.GetEventRecorderFor("test") diff --git a/pkg/manager/manager.go b/pkg/manager/manager.go index 56a34cba6e..5be564507e 100644 --- a/pkg/manager/manager.go +++ b/pkg/manager/manager.go @@ -160,8 +160,12 @@ type Options struct { // use the cache for reads and the client for writes. NewClient NewClientFunc + // EventBroadcaster records Events emitted by the manager and sends them to the Kubernetes API + // Use this to customize the event correlator and spam filter + EventBroadcaster record.EventBroadcaster + // Dependency injection for testing - newRecorderProvider func(config *rest.Config, scheme *runtime.Scheme, logger logr.Logger) (recorder.Provider, error) + newRecorderProvider func(config *rest.Config, scheme *runtime.Scheme, logger logr.Logger, broadcaster record.EventBroadcaster) (recorder.Provider, error) newResourceLock func(config *rest.Config, recorderProvider recorder.Provider, options leaderelection.Options) (resourcelock.Interface, error) newMetricsListener func(addr string) (net.Listener, error) } @@ -231,7 +235,7 @@ func New(config *rest.Config, options Options) (Manager, error) { // Create the recorder provider to inject event recorders for the components. // TODO(directxman12): the log for the event provider should have a context (name, tags, etc) specific // to the particular controller that it's being injected into, rather than a generic one like is here. - recorderProvider, err := options.newRecorderProvider(config, options.Scheme, log.WithName("events")) + recorderProvider, err := options.newRecorderProvider(config, options.Scheme, log.WithName("events"), options.EventBroadcaster) if err != nil { return nil, err } @@ -342,5 +346,9 @@ func setOptionsDefaults(options Options) Options { options.RetryPeriod = &retryPeriod } + if options.EventBroadcaster == nil { + options.EventBroadcaster = record.NewBroadcaster() + } + return options } diff --git a/pkg/manager/manager_test.go b/pkg/manager/manager_test.go index 7819f04955..de771c85b5 100644 --- a/pkg/manager/manager_test.go +++ b/pkg/manager/manager_test.go @@ -30,6 +30,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/rest" "k8s.io/client-go/tools/leaderelection/resourcelock" + "k8s.io/client-go/tools/record" "sigs.k8s.io/controller-runtime/pkg/cache" "sigs.k8s.io/controller-runtime/pkg/cache/informertest" "sigs.k8s.io/controller-runtime/pkg/client" @@ -111,7 +112,7 @@ var _ = Describe("manger.Manager", func() { It("should return an error it can't create a recorder.Provider", func(done Done) { m, err := New(cfg, Options{ - newRecorderProvider: func(config *rest.Config, scheme *runtime.Scheme, logger logr.Logger) (recorder.Provider, error) { + newRecorderProvider: func(config *rest.Config, scheme *runtime.Scheme, logger logr.Logger, broadcaster record.EventBroadcaster) (recorder.Provider, error) { return nil, fmt.Errorf("expected error") }, }) From d8409bdb0709fd029a2fac7a91b7452bf8632f6c Mon Sep 17 00:00:00 2001 From: Alvaro Aleman Date: Tue, 10 Sep 2019 10:49:57 +0200 Subject: [PATCH 09/10] Remove travis.yaml --- .travis.yml | 31 ------------------------------- 1 file changed, 31 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 1562e222fa..0000000000 --- a/.travis.yml +++ /dev/null @@ -1,31 +0,0 @@ -language: go - -os: - - linux - - osx - -cache: - directories: - - $HOME/.cache/go-build - - $GOPATH/pkg/mod - -go: -- "1.12" - -git: - depth: 3 - -go_import_path: sigs.k8s.io/controller-runtime - -install: -- go get -u github.com/golang/dep/cmd/dep -#- go get -u golang.org/x/lint/golint -- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.15.0 - -script: -- GO111MODULE=on TRACE=1 ./hack/check-everything.sh - - -# TBD. Suppressing for now. -notifications: - email: false From b4a78112cfdb9ae6d996b682943bd83a5e5ec92a Mon Sep 17 00:00:00 2001 From: Solly Ross Date: Mon, 16 Sep 2019 16:06:33 -0700 Subject: [PATCH 10/10] Make the release notes script tolerant of merges This makes the release notes script tolerant of manual merges, which helps when calculating the release notes before doing the GitHub branch merge. --- hack/release/release-notes.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hack/release/release-notes.sh b/hack/release/release-notes.sh index 8074e45ddd..4f4a676388 100755 --- a/hack/release/release-notes.sh +++ b/hack/release/release-notes.sh @@ -21,7 +21,16 @@ NEWLINE=" " head_commit=$(git rev-parse HEAD) while read commit_word commit; do + if [[ -z ${commit_word} ]]; then + # skip terminating blank lines + continue + fi read title + if [[ ${title} == "Merge branch '"*"' into release-"* ]]; then + # skip temporary merge commits for calculating release notes + continue + fi + read # skip the blank line read prefix body