@@ -25,6 +25,7 @@ import (
2525 "path/filepath"
2626 "strings"
2727 "sync"
28+ "time"
2829
2930 "go.bytebuilders.dev/license-proxyserver/pkg/common"
3031 "go.bytebuilders.dev/license-proxyserver/pkg/storage"
@@ -88,10 +89,7 @@ func (r *LicenseAcquirer) Reconcile(ctx context.Context, request reconcile.Reque
8889 }
8990 }
9091 if cid != "" && len (features ) > 0 {
91- err = r .reconcile (ctx , managedCluster .Name , cid , features )
92- if err != nil {
93- return reconcile.Result {}, err
94- }
92+ return r .reconcile (ctx , managedCluster .Name , cid , features )
9593 }
9694
9795 return reconcile.Result {}, nil
@@ -116,7 +114,7 @@ func (r *LicenseAcquirer) getLicenseRegistry(cid string) (*storage.LicenseRegist
116114 return reg , nil
117115}
118116
119- func (r * LicenseAcquirer ) reconcile (ctx context.Context , clusterName , cid string , features []string ) error {
117+ func (r * LicenseAcquirer ) reconcile (ctx context.Context , clusterName , cid string , features []string ) (reconcile. Result , error ) {
120118 sec := core.Secret {
121119 ObjectMeta : metav1.ObjectMeta {
122120 Name : common .LicenseSecret ,
@@ -130,14 +128,15 @@ func (r *LicenseAcquirer) reconcile(ctx context.Context, clusterName, cid string
130128 } else if apierrors .IsNotFound (err ) {
131129 sec .Data = map [string ][]byte {}
132130 } else {
133- return err
131+ return reconcile. Result {}, err
134132 }
135133
136134 var errList []error
135+ var earliestExpired time.Time
137136
138137 reg , err := r .getLicenseRegistry (cid )
139138 if err != nil {
140- return err
139+ return reconcile. Result {}, err
141140 }
142141 for _ , feature := range features {
143142 l , found := reg .LicenseForFeature (feature )
@@ -156,6 +155,9 @@ func (r *LicenseAcquirer) reconcile(ctx context.Context, clusterName, cid string
156155 }
157156 if l != nil && l .Status == v1alpha1 .LicenseActive {
158157 sec .Data [l .PlanName ] = l .Data
158+ if earliestExpired .IsZero () || earliestExpired .After (l .NotAfter .Time ) {
159+ earliestExpired = l .NotAfter .Time
160+ }
159161 }
160162 }
161163
@@ -165,12 +167,15 @@ func (r *LicenseAcquirer) reconcile(ctx context.Context, clusterName, cid string
165167 errList = append (errList , r .Create (context .TODO (), & sec ))
166168 }
167169
168- return utilerrors .NewAggregate (errList )
170+ if ! earliestExpired .IsZero () {
171+ return reconcile.Result {
172+ RequeueAfter : time .Until (earliestExpired .Add (- storage .LicenseAcquisitionBuffer )),
173+ }, utilerrors .NewAggregate (errList )
174+ }
175+ return reconcile.Result {}, utilerrors .NewAggregate (errList )
169176}
170177
171178func (r * LicenseAcquirer ) getNewLicense (ctx context.Context , cid string , features []string ) (* v1alpha1.License , * v1alpha1.Contract , error ) {
172- logger := log .FromContext (ctx )
173-
174179 lc , err := pc .NewClient (r .BaseURL , r .Token , cid , r .CaCert , r .InsecureSkipTLSVerify , fmt .Sprintf ("license-proxyserver-manager/%s" , v .Version .Version ))
175180 if err != nil {
176181 return nil , nil , err
@@ -180,7 +185,6 @@ func (r *LicenseAcquirer) getNewLicense(ctx context.Context, cid string, feature
180185 if err != nil {
181186 return nil , nil , err
182187 }
183- logger .Info ("acquired new license" , "cid" , cid , "features" , strings .Join (features , "," ))
184188
185189 caData , err := info .LoadLicenseCA ()
186190 if err != nil {
@@ -200,5 +204,13 @@ func (r *LicenseAcquirer) getNewLicense(ctx context.Context, cid string, feature
200204 return nil , nil , err
201205 }
202206
207+ klog .InfoS ("acquired new license" ,
208+ "cluster" , cid ,
209+ "id" , l .ID ,
210+ "product" , l .ProductLine ,
211+ "plan" , l .PlanName ,
212+ "tier" , l .TierName ,
213+ "expiry" , l .NotAfter .UTC ().Format (time .RFC822 ),
214+ )
203215 return & l , con , nil
204216}
0 commit comments