Skip to content

Commit 630381a

Browse files
committed
Fix panic
Signed-off-by: Tamal Saha <tamal@appscode.com>
1 parent 657cee3 commit 630381a

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

lib/nats.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,21 @@ func isNatsAuthError(e string) bool {
116116
return false
117117
}
118118

119-
func (c *NatsClient) GetLicenseID() string {
119+
func (c *NatsClient) GetLicenseID() (string, error) {
120120
c.mu.Lock()
121121
defer c.mu.Unlock()
122122

123+
if c.nc == nil {
124+
if err := c.connect(); err != nil {
125+
return "", err
126+
}
127+
}
128+
123129
if c.l.Status == v1alpha1.LicenseActive && time.Now().After(c.l.NotAfter.Time) {
124130
license, _ := c.le.LoadLicense()
125131
c.l = &license
126132
}
127-
return c.l.ID
133+
return c.l.ID, nil
128134
}
129135

130136
func (c *NatsClient) connect() error {

lib/publisher.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ func (p *EventPublisher) ForGVK(informer Informer, gvk schema.GroupVersionKind)
146146
if err != nil {
147147
return nil, err
148148
}
149-
ev.LicenseID = p.c.GetLicenseID()
150-
return ev, nil
149+
ev.LicenseID, err = p.c.GetLicenseID()
150+
return ev, err
151151
},
152152
}
153153
_, _ = informer.AddEventHandlerWithResyncPeriod(h, eventInterval)
@@ -212,7 +212,10 @@ func (p *EventPublisher) setupSiteInfoPublisher(cfg *rest.Config, kc kubernetes.
212212
identitylib.RefreshNodeStats(p.si, nodes)
213213
p.siMutex.Unlock()
214214

215-
licenseID := p.c.GetLicenseID()
215+
licenseID, err := p.c.GetLicenseID()
216+
if err != nil {
217+
return nil, err
218+
}
216219
p.si.Product.LicenseID = licenseID
217220
p.si.Name = fmt.Sprintf("%s.%s", licenseID, p.si.Product.ProductName)
218221
ev := &api.Event{

0 commit comments

Comments
 (0)