@@ -63,9 +63,14 @@ type LeaseCandidate struct {
63
63
preferredStrategies []v1.CoordinatedLeaseStrategy
64
64
}
65
65
66
+ // NewCandidate creates new LeaseCandidate controller that creates a
67
+ // LeaseCandidate object if it does not exist and watches changes
68
+ // to the corresponding object and renews if PingTime is set.
69
+ // WARNING: This is an ALPHA feature. Ensure that the CoordinatedLeaderElection
70
+ // feature gate is on.
66
71
func NewCandidate (clientset kubernetes.Interface ,
67
- candidateName string ,
68
72
candidateNamespace string ,
73
+ candidateName string ,
69
74
targetLease string ,
70
75
binaryVersion , emulationVersion string ,
71
76
preferredStrategies []v1.CoordinatedLeaseStrategy ,
@@ -144,7 +149,6 @@ func (c *LeaseCandidate) processNextWorkItem(ctx context.Context) bool {
144
149
}
145
150
146
151
utilruntime .HandleError (err )
147
- klog .Infof ("processNextWorkItem.AddRateLimited: %v" , key )
148
152
c .queue .AddRateLimited (key )
149
153
150
154
return true
@@ -161,17 +165,16 @@ func (c *LeaseCandidate) ensureLease(ctx context.Context) error {
161
165
if apierrors .IsNotFound (err ) {
162
166
klog .V (2 ).Infof ("Creating lease candidate" )
163
167
// lease does not exist, create it.
164
- leaseToCreate := c .newLease ()
165
- _ , err := c .leaseClient .Create (ctx , leaseToCreate , metav1.CreateOptions {})
166
- if err != nil {
168
+ leaseToCreate := c .newLeaseCandidate ()
169
+ if _ , err := c .leaseClient .Create (ctx , leaseToCreate , metav1.CreateOptions {}); err != nil {
167
170
return err
168
171
}
169
172
klog .V (2 ).Infof ("Created lease candidate" )
170
173
return nil
171
174
} else if err != nil {
172
175
return err
173
176
}
174
- klog .V (2 ).Infof ("lease candidate exists.. renewing " )
177
+ klog .V (2 ).Infof ("lease candidate exists. Renewing. " )
175
178
clone := lease .DeepCopy ()
176
179
clone .Spec .RenewTime = & metav1.MicroTime {Time : c .clock .Now ()}
177
180
clone .Spec .PingTime = nil
@@ -182,8 +185,8 @@ func (c *LeaseCandidate) ensureLease(ctx context.Context) error {
182
185
return nil
183
186
}
184
187
185
- func (c * LeaseCandidate ) newLease () * v1alpha1.LeaseCandidate {
186
- lease := & v1alpha1.LeaseCandidate {
188
+ func (c * LeaseCandidate ) newLeaseCandidate () * v1alpha1.LeaseCandidate {
189
+ lc := & v1alpha1.LeaseCandidate {
187
190
ObjectMeta : metav1.ObjectMeta {
188
191
Name : c .name ,
189
192
Namespace : c .namespace ,
@@ -195,6 +198,6 @@ func (c *LeaseCandidate) newLease() *v1alpha1.LeaseCandidate {
195
198
PreferredStrategies : c .preferredStrategies ,
196
199
},
197
200
}
198
- lease .Spec .RenewTime = & metav1.MicroTime {Time : c .clock .Now ()}
199
- return lease
201
+ lc .Spec .RenewTime = & metav1.MicroTime {Time : c .clock .Now ()}
202
+ return lc
200
203
}
0 commit comments