@@ -14,6 +14,7 @@ import (
1414 "strings"
1515 "time"
1616
17+ license_reporting "github.com/nginxinc/kubernetes-ingress/internal/license_reporting"
1718 nl "github.com/nginxinc/kubernetes-ingress/internal/logger"
1819 "github.com/nginxinc/kubernetes-ingress/internal/metrics/collectors"
1920
@@ -101,7 +102,7 @@ type Manager interface {
101102 DeleteKeyValStateFiles (virtualServerName string )
102103}
103104
104- // LocalManager updates NGINX configuration, starts, reloads and quits NGINX,
105+ // LocalManager updates NGINX configuration, starts, reloads and quits NGINX, updates License Reporting file
105106// updates NGINX Plus upstream servers. It assumes that NGINX is running in the same container.
106107type LocalManager struct {
107108 confdPath string
@@ -119,15 +120,18 @@ type LocalManager struct {
119120 plusClient * client.NginxClient
120121 plusConfigVersionCheckClient * http.Client
121122 metricsCollector collectors.ManagerCollector
123+ licenseReporter * license_reporting.LicenseReporter
124+ licenseReporterCancel context.CancelFunc
122125 OpenTracing bool
123126 appProtectPluginPid int
124127 appProtectDosAgentPid int
125128 agentPid int
126129 logger * slog.Logger
130+ nginxPlus bool
127131}
128132
129133// NewLocalManager creates a LocalManager.
130- func NewLocalManager (ctx context.Context , confPath string , debug bool , mc collectors.ManagerCollector , timeout time.Duration ) * LocalManager {
134+ func NewLocalManager (ctx context.Context , confPath string , debug bool , mc collectors.ManagerCollector , lr * license_reporting. LicenseReporter , timeout time.Duration , nginxPlus bool ) * LocalManager {
131135 l := nl .LoggerFromContext (ctx )
132136 verifyConfigGenerator , err := newVerifyConfigGenerator ()
133137 if err != nil {
@@ -148,6 +152,8 @@ func NewLocalManager(ctx context.Context, confPath string, debug bool, mc collec
148152 configVersion : 0 ,
149153 verifyClient : newVerifyClient (timeout ),
150154 metricsCollector : mc ,
155+ licenseReporter : lr ,
156+ nginxPlus : nginxPlus ,
151157 logger : l ,
152158 }
153159
@@ -296,6 +302,19 @@ func (lm *LocalManager) ClearAppProtectFolder(name string) {
296302
297303// Start starts NGINX.
298304func (lm * LocalManager ) Start (done chan error ) {
305+ if lm .nginxPlus {
306+ isR33OrGreater , versionErr := lm .Version ().PlusGreaterThanOrEqualTo ("nginx-plus-r33" )
307+ if versionErr != nil {
308+ nl .Errorf (lm .logger , "Error determining whether nginx version is >= r33: %v" , versionErr )
309+ }
310+ if isR33OrGreater {
311+ ctx , cancel := context .WithCancel (context .Background ())
312+ nl .ContextWithLogger (ctx , lm .logger )
313+ go lm .licenseReporter .Start (ctx )
314+ lm .licenseReporterCancel = cancel
315+ }
316+ }
317+
299318 nl .Debug (lm .logger , "Starting nginx" )
300319
301320 binaryFilename := getBinaryFileName (lm .debug )
@@ -347,6 +366,16 @@ func (lm *LocalManager) Reload(isEndpointsUpdate bool) error {
347366func (lm * LocalManager ) Quit () {
348367 nl .Debugf (lm .logger , "Quitting nginx" )
349368
369+ if lm .nginxPlus {
370+ isR33OrGreater , err := lm .Version ().PlusGreaterThanOrEqualTo ("nginx-plus-r33" )
371+ if err != nil {
372+ nl .Errorf (lm .logger , "Error determining whether nginx version is >= r33: %v" , err )
373+ }
374+ if isR33OrGreater && lm .licenseReporterCancel != nil {
375+ lm .licenseReporterCancel ()
376+ }
377+ }
378+
350379 binaryFilename := getBinaryFileName (lm .debug )
351380 if err := shellOut (lm .logger , fmt .Sprintf ("%v -s %v" , binaryFilename , "quit" )); err != nil {
352381 nl .Fatalf (lm .logger , "Failed to quit nginx: %v" , err )
0 commit comments