Skip to content

Commit 188fe5b

Browse files
committed
Drop event recorder from shard lease lock
1 parent 027261f commit 188fe5b

File tree

6 files changed

+13
-26
lines changed

6 files changed

+13
-26
lines changed

cmd/shard/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (o *options) run(ctx context.Context) error {
126126
}
127127

128128
log.Info("Setting up shard lease")
129-
shardLease, err := shardlease.NewResourceLock(restConfig, nil, shardlease.Options{
129+
shardLease, err := shardlease.NewResourceLock(restConfig, shardlease.Options{
130130
ControllerRingName: o.controllerRingName,
131131
LeaseNamespace: o.leaseNamespace, // optional, can be empty
132132
ShardName: o.shardName, // optional, can be empty

docs/implement-sharding.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ import (
135135
func run() error {
136136
restConfig := config.GetConfigOrDie()
137137
138-
shardLease, err := shardlease.NewResourceLock(restConfig, nil, shardlease.Options{
138+
shardLease, err := shardlease.NewResourceLock(restConfig, shardlease.Options{
139139
ControllerRingName: "my-controllerring",
140140
})
141141
if err != nil {

pkg/shard/lease/lease.go

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"os"
2626

2727
coordinationv1 "k8s.io/api/coordination/v1"
28-
corev1 "k8s.io/api/core/v1"
2928
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3029
coordinationv1client "k8s.io/client-go/kubernetes/typed/coordination/v1"
3130
"k8s.io/client-go/rest"
@@ -50,7 +49,7 @@ type Options struct {
5049
// NewResourceLock returns a new resource lock that implements the shard lease.
5150
// Pass this to the leader elector, e.g., leaderelection.LeaderElectionConfig.Lock (if using plain client-go) or
5251
// manager.Options.LeaderElectionResourceLockInterface (if using controller-runtime).
53-
func NewResourceLock(config *rest.Config, eventRecorder resourcelock.EventRecorder, options Options) (resourcelock.Interface, error) {
52+
func NewResourceLock(config *rest.Config, options Options) (resourcelock.Interface, error) {
5453
// Construct client for leader election
5554
rest.AddUserAgent(config, "shard-lease")
5655

@@ -89,8 +88,6 @@ func NewResourceLock(config *rest.Config, eventRecorder resourcelock.EventRecord
8988
Client: coordinationClient,
9089
LockConfig: resourcelock.ResourceLockConfig{
9190
Identity: options.ShardName,
92-
// eventRecorder is optional
93-
EventRecorder: eventRecorder,
9491
},
9592
Labels: map[string]string{
9693
shardingv1alpha1.LabelControllerRing: options.ControllerRingName,
@@ -158,18 +155,8 @@ func (ll *LeaseLock) Update(ctx context.Context, ler resourcelock.LeaderElection
158155
return nil
159156
}
160157

161-
// RecordEvent in leader election while adding meta-data
162-
func (ll *LeaseLock) RecordEvent(s string) {
163-
if ll.LockConfig.EventRecorder == nil {
164-
return
165-
}
166-
events := fmt.Sprintf("%v %v", ll.LockConfig.Identity, s)
167-
subject := &coordinationv1.Lease{ObjectMeta: ll.lease.ObjectMeta}
168-
// Populate the type meta, so we don't have to get it from the schema
169-
subject.Kind = "Lease"
170-
subject.APIVersion = coordinationv1.SchemeGroupVersion.String()
171-
ll.LockConfig.EventRecorder.Eventf(subject, corev1.EventTypeNormal, "LeaderElection", events)
172-
}
158+
// RecordEvent does nothing, as recording events on shard leases is not meaningful.
159+
func (ll *LeaseLock) RecordEvent(string) {}
173160

174161
// Describe is used to convert details on current resource lock
175162
// into a string

pkg/shard/lease/lease_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ var _ = Describe("LeaseLock", func() {
7575
It("should fail if ControllerRingName is empty", func() {
7676
options.ControllerRingName = ""
7777

78-
Expect(NewResourceLock(restConfig, nil, options)).Error().To(MatchError("ControllerRingName is required"))
78+
Expect(NewResourceLock(restConfig, options)).Error().To(MatchError("ControllerRingName is required"))
7979
})
8080

8181
It("should use the configured namespace and name", func() {
82-
resourceLock, err := NewResourceLock(restConfig, nil, options)
82+
resourceLock, err := NewResourceLock(restConfig, options)
8383
Expect(err).NotTo(HaveOccurred())
8484

8585
leaseLock := resourceLock.(*LeaseLock)
@@ -93,7 +93,7 @@ var _ = Describe("LeaseLock", func() {
9393
hostname, err := os.Hostname()
9494
Expect(err).NotTo(HaveOccurred())
9595

96-
resourceLock, err := NewResourceLock(restConfig, nil, options)
96+
resourceLock, err := NewResourceLock(restConfig, options)
9797
Expect(err).NotTo(HaveOccurred())
9898

9999
leaseLock := resourceLock.(*LeaseLock)
@@ -104,7 +104,7 @@ var _ = Describe("LeaseLock", func() {
104104
It("should default the namespace to the in-cluster namespace", func() {
105105
options.LeaseNamespace = ""
106106

107-
resourceLock, err := NewResourceLock(restConfig, nil, options)
107+
resourceLock, err := NewResourceLock(restConfig, options)
108108
Expect(err).NotTo(HaveOccurred())
109109

110110
leaseLock := resourceLock.(*LeaseLock)
@@ -115,7 +115,7 @@ var _ = Describe("LeaseLock", func() {
115115
options.LeaseNamespace = ""
116116
fsys = fstest.MapFS{}
117117

118-
Expect(NewResourceLock(restConfig, nil, options)).Error().To(MatchError(And(
118+
Expect(NewResourceLock(restConfig, options)).Error().To(MatchError(And(
119119
ContainSubstring("not running in cluster"),
120120
ContainSubstring("please specify LeaseNamespace"),
121121
)))
@@ -132,7 +132,7 @@ var _ = Describe("LeaseLock", func() {
132132

133133
BeforeEach(func() {
134134
var err error
135-
lock, err = NewResourceLock(&rest.Config{}, nil, Options{
135+
lock, err = NewResourceLock(&rest.Config{}, Options{
136136
ControllerRingName: controllerRingName,
137137
LeaseNamespace: namespace,
138138
ShardName: shardName,

test/integration/shard/lease/lease_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ var _ = Describe("Shard lease", func() {
6868
}, OncePerOrdered)
6969

7070
JustBeforeEach(func() {
71-
shardLease, err := shardlease.NewResourceLock(restConfig, nil, leaseOptions)
71+
shardLease, err := shardlease.NewResourceLock(restConfig, leaseOptions)
7272
Expect(err).NotTo(HaveOccurred())
7373
mgrOptions.LeaderElectionResourceLockInterface = shardLease
7474

webhosting-operator/cmd/webhosting-operator/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ func (o *options) applyOptionsOverrides() error {
273273

274274
// SHARD LEASE
275275
o.controllerRingName = "webhosting-operator"
276-
shardLease, err := shardlease.NewResourceLock(o.restConfig, nil, shardlease.Options{
276+
shardLease, err := shardlease.NewResourceLock(o.restConfig, shardlease.Options{
277277
ControllerRingName: o.controllerRingName,
278278
})
279279
if err != nil {

0 commit comments

Comments
 (0)