Skip to content

Commit b80d42e

Browse files
committed
chore: Add a license manager stub
1 parent c8384c6 commit b80d42e

File tree

5 files changed

+115
-17
lines changed

5 files changed

+115
-17
lines changed

internal/licensemanager/manager.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Implementation of the license manager for unlocking enterprise features
2+
package licensemanager
3+
4+
import (
5+
"context"
6+
7+
"github.com/go-logr/logr"
8+
"github.com/l7mp/stunner-gateway-operator/internal/event"
9+
licensecfg "github.com/l7mp/stunner/pkg/config/license"
10+
)
11+
12+
var licenseManagerConstructor = NewStubManager
13+
14+
// Manager is a global license manager that encapsulates the license management logics
15+
type Manager interface {
16+
// Start runs the license manager.
17+
Start(context.Context) error
18+
// Validate checks whether a client is entitled to use a feature.
19+
Validate(feature licensecfg.Feature) bool
20+
// SubscriptionType returns the current subscription type (e.g., free, member, enterprise).
21+
SubscriptionType() string
22+
// SetOperatorChannel sets up the operator channel where the manager can send rendering
23+
SetOperatorChannel(c chan event.Event)
24+
// LastError returns the last license manager error.
25+
LastError() error
26+
}
27+
28+
type Config struct {
29+
CustomerKey string
30+
LicenseManagerClient any
31+
Logger logr.Logger
32+
}
33+
34+
func NewManager(config Config) Manager {
35+
return licenseManagerConstructor(config)
36+
}

internal/licensemanager/stub.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package licensemanager
2+
3+
import (
4+
"context"
5+
6+
"github.com/l7mp/stunner-gateway-operator/internal/event"
7+
licensecfg "github.com/l7mp/stunner/pkg/config/license"
8+
)
9+
10+
// license manager stub
11+
type stubMgr struct{}
12+
13+
func NewStubManager(_ Config) Manager { return &stubMgr{} }
14+
15+
func (_ *stubMgr) Start(_ context.Context) error { return nil }
16+
func (_ *stubMgr) Validate(_ licensecfg.Feature) bool { return true }
17+
func (_ *stubMgr) SubscriptionType() string { return "free" }
18+
func (_ *stubMgr) LastError() error { return nil }
19+
func (_ *stubMgr) SetOperatorChannel(_ chan event.Event) {}

internal/renderer/renderer.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,19 @@ import (
88

99
"github.com/l7mp/stunner-gateway-operator/internal/config"
1010
"github.com/l7mp/stunner-gateway-operator/internal/event"
11+
licensemgr "github.com/l7mp/stunner-gateway-operator/internal/licensemanager"
1112
)
1213

1314
type RendererConfig struct {
14-
Scheme *runtime.Scheme
15-
Logger logr.Logger
15+
Scheme *runtime.Scheme
16+
LicenseManager licensemgr.Manager
17+
Logger logr.Logger
1618
}
1719

1820
type Renderer struct {
1921
ctx context.Context
2022
scheme *runtime.Scheme
23+
licmgr licensemgr.Manager
2124
gen int
2225
renderCh, operatorCh chan event.Event
2326
*config.ProgressTracker
@@ -28,6 +31,7 @@ type Renderer struct {
2831
func NewRenderer(cfg RendererConfig) *Renderer {
2932
return &Renderer{
3033
scheme: cfg.Scheme,
34+
licmgr: cfg.LicenseManager,
3135
renderCh: make(chan event.Event, 10),
3236
gen: 0,
3337
ProgressTracker: config.NewProgressTracker(),

main.go

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import (
4444
"github.com/l7mp/stunner/pkg/buildinfo"
4545

4646
"github.com/l7mp/stunner-gateway-operator/internal/config"
47+
licensemgr "github.com/l7mp/stunner-gateway-operator/internal/licensemanager"
4748
"github.com/l7mp/stunner-gateway-operator/internal/operator"
4849
"github.com/l7mp/stunner-gateway-operator/internal/renderer"
4950
"github.com/l7mp/stunner-gateway-operator/internal/updater"
@@ -54,8 +55,9 @@ import (
5455
)
5556

5657
const (
57-
envVarMode = "STUNNER_GATEWAY_OPERATOR_DATAPLANE_MODE"
58-
envVarAddress = "STUNNER_GATEWAY_OPERATOR_ADDRESS"
58+
envVarMode = "STUNNER_GATEWAY_OPERATOR_DATAPLANE_MODE"
59+
envVarAddress = "STUNNER_GATEWAY_OPERATOR_ADDRESS"
60+
envVarCustomerKey = "CUSTOMER_KEY"
5961
)
6062

6163
var (
@@ -131,6 +133,13 @@ func main() {
131133
config.DataplaneMode = config.NewDataplaneMode(dataplaneMode)
132134
setupLog.Info("dataplane mode", "mode", config.DataplaneMode.String())
133135

136+
customerKey, keyStatus := "", "MISSING"
137+
if key, ok := os.LookupEnv(envVarCustomerKey); ok {
138+
customerKey = key
139+
keyStatus = "AVAILABLE"
140+
}
141+
setupLog.Info("subscriber key", "status", keyStatus)
142+
134143
// CDS address not overrridden on the command line: use env var
135144
config.ConfigDiscoveryAddress = cdsAddr
136145
if podAddr, ok := os.LookupEnv(envVarAddress); ok {
@@ -176,10 +185,17 @@ func main() {
176185
os.Exit(1)
177186
}
178187

179-
setupLog.Info("setting up STUNner config renderer")
188+
setupLog.Info("setting up license manager")
189+
m := licensemgr.NewManager(licensemgr.Config{
190+
CustomerKey: customerKey,
191+
Logger: logger,
192+
})
193+
194+
setupLog.Info("setting up config renderer")
180195
r := renderer.NewRenderer(renderer.RendererConfig{
181-
Scheme: scheme,
182-
Logger: logger,
196+
Scheme: scheme,
197+
LicenseManager: m,
198+
Logger: logger,
183199
})
184200

185201
setupLog.Info("setting up updater client")
@@ -201,6 +217,7 @@ func main() {
201217
Logger: logger,
202218
})
203219

220+
m.SetOperatorChannel(op.GetOperatorChannel())
204221
r.SetOperatorChannel(op.GetOperatorChannel())
205222
u.SetAckChannel(op.GetOperatorChannel())
206223
op.SetProgressReporters(r, u, c)
@@ -209,15 +226,27 @@ func main() {
209226
mgrCtx, mgrCancel := context.WithCancel(context.Background())
210227
defer mgrCancel()
211228

212-
setupLog.Info("starting renderer thread")
229+
setupLog.Info("starting the license manager")
230+
if err := m.Start(mgrCtx); err != nil {
231+
setupLog.Error(err, "error running the license manager")
232+
os.Exit(1)
233+
}
234+
235+
setupLog.Info("starting the license manager")
236+
if err := m.Start(mgrCtx); err != nil {
237+
setupLog.Error(err, "error running the license manager")
238+
os.Exit(1)
239+
}
240+
241+
setupLog.Info("starting the renderer")
213242
if err := r.Start(mgrCtx); err != nil {
214-
setupLog.Error(err, "problem running renderer")
243+
setupLog.Error(err, "error running the renderer")
215244
os.Exit(1)
216245
}
217246

218-
setupLog.Info("starting updater thread")
247+
setupLog.Info("starting the updater")
219248
if err := u.Start(mgrCtx); err != nil {
220-
setupLog.Error(err, "could not run updater")
249+
setupLog.Error(err, "error running the updater")
221250
os.Exit(1)
222251
}
223252

@@ -228,13 +257,13 @@ func main() {
228257
}
229258

230259
opCtx := ctrl.SetupSignalHandler()
231-
setupLog.Info("starting operator thread")
260+
setupLog.Info("starting the operator")
232261
if err := op.Start(opCtx, mgrCancel); err != nil {
233262
setupLog.Error(err, "problem running operator")
234263
os.Exit(1)
235264
}
236265

237-
setupLog.Info("starting Kubernetes controller manager")
266+
setupLog.Info("starting the Kubernetes controller manager")
238267
if err := mgr.Start(mgrCtx); err != nil {
239268
setupLog.Error(err, "problem running manager")
240269
// no way to gracefully terminate: give up and exit with an error

test/integration_suite_test.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import (
4444
gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
4545

4646
"github.com/l7mp/stunner-gateway-operator/internal/config"
47+
licensemgr "github.com/l7mp/stunner-gateway-operator/internal/licensemanager"
4748
"github.com/l7mp/stunner-gateway-operator/internal/operator"
4849
"github.com/l7mp/stunner-gateway-operator/internal/renderer"
4950
"github.com/l7mp/stunner-gateway-operator/internal/testutils"
@@ -54,7 +55,8 @@ import (
5455
stnrgwv1 "github.com/l7mp/stunner-gateway-operator/api/v1"
5556
)
5657

57-
var _ = fmt.Sprintf("%d", 1)
58+
// Empty subscriber key for testing
59+
var customerTestKey string
5860

5961
// Define utility constants for object names and testing timeouts/durations and intervals.
6062
const (
@@ -173,10 +175,17 @@ func initOperator(mgrCtx, opCtx context.Context) {
173175
})
174176
Expect(err).NotTo(HaveOccurred())
175177

176-
setupLog.Info("setting up STUNner config renderer")
178+
setupLog.Info("setting up license manager")
179+
m := licensemgr.NewManager(licensemgr.Config{
180+
CustomerKey: customerTestKey,
181+
Logger: ctrl.Log,
182+
})
183+
184+
setupLog.Info("setting up config renderer")
177185
r := renderer.NewRenderer(renderer.RendererConfig{
178-
Scheme: scheme,
179-
Logger: ctrl.Log,
186+
Scheme: scheme,
187+
LicenseManager: m,
188+
Logger: ctrl.Log,
180189
})
181190
Expect(r).NotTo(BeNil())
182191

@@ -202,6 +211,7 @@ func initOperator(mgrCtx, opCtx context.Context) {
202211
Logger: ctrl.Log,
203212
})
204213

214+
m.SetOperatorChannel(op.GetOperatorChannel())
205215
r.SetOperatorChannel(op.GetOperatorChannel())
206216
u.SetAckChannel(op.GetOperatorChannel())
207217
op.SetProgressReporters(r, u, c)

0 commit comments

Comments
 (0)