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:
Nikolay Edigaryev
2023-07-26 17:28:38 +04:00
committed by GitHub
parent a52c205c34
commit fd88ce5890
3 changed files with 43 additions and 6 deletions
+23
View File
@@ -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()",