@@ -63,9 +63,14 @@ type LeaseCandidate struct {
6363 preferredStrategies []v1.CoordinatedLeaseStrategy
6464}
6565
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.
6671func NewCandidate (clientset kubernetes.Interface ,
67- candidateName string ,
6872 candidateNamespace string ,
73+ candidateName string ,
6974 targetLease string ,
7075 binaryVersion , emulationVersion string ,
7176 preferredStrategies []v1.CoordinatedLeaseStrategy ,
@@ -144,7 +149,6 @@ func (c *LeaseCandidate) processNextWorkItem(ctx context.Context) bool {
144149 }
145150
146151 utilruntime .HandleError (err )
147- klog .Infof ("processNextWorkItem.AddRateLimited: %v" , key )
148152 c .queue .AddRateLimited (key )
149153
150154 return true
@@ -161,17 +165,16 @@ func (c *LeaseCandidate) ensureLease(ctx context.Context) error {
161165 if apierrors .IsNotFound (err ) {
162166 klog .V (2 ).Infof ("Creating lease candidate" )
163167 // 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 {
167170 return err
168171 }
169172 klog .V (2 ).Infof ("Created lease candidate" )
170173 return nil
171174 } else if err != nil {
172175 return err
173176 }
174- klog .V (2 ).Infof ("lease candidate exists.. renewing " )
177+ klog .V (2 ).Infof ("lease candidate exists. Renewing. " )
175178 clone := lease .DeepCopy ()
176179 clone .Spec .RenewTime = & metav1.MicroTime {Time : c .clock .Now ()}
177180 clone .Spec .PingTime = nil
@@ -182,8 +185,8 @@ func (c *LeaseCandidate) ensureLease(ctx context.Context) error {
182185 return nil
183186}
184187
185- func (c * LeaseCandidate ) newLease () * v1alpha1.LeaseCandidate {
186- lease := & v1alpha1.LeaseCandidate {
188+ func (c * LeaseCandidate ) newLeaseCandidate () * v1alpha1.LeaseCandidate {
189+ lc := & v1alpha1.LeaseCandidate {
187190 ObjectMeta : metav1.ObjectMeta {
188191 Name : c .name ,
189192 Namespace : c .namespace ,
@@ -195,6 +198,6 @@ func (c *LeaseCandidate) newLease() *v1alpha1.LeaseCandidate {
195198 PreferredStrategies : c .preferredStrategies ,
196199 },
197200 }
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
200203}
0 commit comments