mirror of
https://github.com/cirruslabs/orchard.git
synced 2026-10-18 22:48:57 +02:00
Introduce ORCHARD_LICENSE_TIER environment variable (#111)
* Introduce ORCHARD_LICENSE_TIER environment variable * Only parse ORCHARD_LICENSE_TIER if it was provided
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
"google.golang.org/grpc/keepalive"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -29,6 +30,12 @@ var (
|
||||
ErrAdminTaskFailed = errors.New("controller administrative task failed")
|
||||
)
|
||||
|
||||
const (
|
||||
maxWorkersPerDefaultLicense = 4
|
||||
maxWorkersPerGoldLicense = 20
|
||||
maxWorkersPerPlatinumLicense = 200
|
||||
)
|
||||
|
||||
type Controller struct {
|
||||
dataDir *DataDir
|
||||
listenAddr string
|
||||
@@ -44,6 +51,7 @@ type Controller struct {
|
||||
proxy *proxy.Proxy
|
||||
enableSwaggerDocs bool
|
||||
workerOfflineTimeout time.Duration
|
||||
maxWorkersPerLicense uint
|
||||
|
||||
rpc.UnimplementedControllerServer
|
||||
}
|
||||
@@ -53,6 +61,7 @@ func New(opts ...Option) (*Controller, error) {
|
||||
workerNotifier: notifier.NewNotifier(),
|
||||
proxy: proxy.NewProxy(),
|
||||
workerOfflineTimeout: 3 * time.Minute,
|
||||
maxWorkersPerLicense: maxWorkersPerDefaultLicense,
|
||||
}
|
||||
|
||||
// Apply options
|
||||
@@ -60,6 +69,20 @@ func New(opts ...Option) (*Controller, error) {
|
||||
opt(controller)
|
||||
}
|
||||
|
||||
// Apply environment variables
|
||||
orchardLicenseTier, ok := os.LookupEnv("ORCHARD_LICENSE_TIER")
|
||||
if ok {
|
||||
switch orchardLicenseTier {
|
||||
case "gold":
|
||||
controller.maxWorkersPerLicense = maxWorkersPerGoldLicense
|
||||
case "platinum":
|
||||
controller.maxWorkersPerLicense = maxWorkersPerPlatinumLicense
|
||||
default:
|
||||
return nil, fmt.Errorf("%w: invalid ORCHARD_LICENSE_TIER value: %q",
|
||||
ErrInitFailed, orchardLicenseTier)
|
||||
}
|
||||
}
|
||||
|
||||
// Apply defaults
|
||||
if controller.dataDir == nil {
|
||||
return nil, fmt.Errorf("%w: please specify the data directory path with WithDataDir()",
|
||||
|
||||
Reference in New Issue
Block a user