Skip to content

Commit

Permalink
Support custom domain
Browse files Browse the repository at this point in the history
  • Loading branch information
assafad1 committed Sep 26, 2024
1 parent 156f772 commit 28c8503
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Add the region and api-key as environment variables (or later as flags).
$ export CORALOGIX_API_KEY="xxx-xxx-xxx"
$ export CORALOGIX_REGION = "EU2"
```
For private domain the `domain` field or the environment variables `CORALOGIX_DOMAIN` have to be defined.

Run the operator locally
```sh
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ make install
$ export CORALOGIX_API_KEY="<api-key>"
$ export CORALOGIX_REGION="<region>"
```
For private domain the `domain` field or the environment variables `CORALOGIX_DOMAIN` have to be defined.

3. Build and push your image to the location specified by `IMG`:
```sh
Expand Down
32 changes: 27 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,13 @@ func main() {
"Enabling this will ensure there is only one active controller manager.")

region := os.Getenv("CORALOGIX_REGION")
flag.StringVar(&region, "region", region, fmt.Sprintf("The region of your Coralogix cluster. Can be one of %q.", validRegions))
flag.StringVar(&region, "region", region, fmt.Sprintf("The region of your Coralogix cluster. Can be one of %q. Conflicts with 'domain'.", validRegions))

domain := os.Getenv("CORALOGIX_DOMAIN")
flag.StringVar(&domain, "domain", domain, "The domain of your Coralogix cluster. Conflicts with 'region'.")

apiKey := os.Getenv("CORALOGIX_API_KEY")
flag.StringVar(&apiKey, "api-key", apiKey, "The proper api-key based on your Coralogix cluster's region")
flag.StringVar(&apiKey, "api-key", apiKey, "The proper api-key based on your Coralogix cluster's region.")

var prometheusRuleController bool
flag.BoolVar(&prometheusRuleController, "prometheus-rule-controller", true, "Determine if the prometheus rule controller should be started. Default is true.")
Expand All @@ -104,12 +107,32 @@ func main() {

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

if !slices.Contains(validRegions, region) {
err := fmt.Errorf("region value is '%s', but can be one of %q", region, validRegions)
if region != "" && domain != "" {
err := fmt.Errorf("region and domain flags are mutually exclusive")
setupLog.Error(err, "invalid arguments for running operator")
os.Exit(1)
}

if region == "" && domain == "" {
err := fmt.Errorf("region or domain must be set")
setupLog.Error(err, "invalid arguments for running operator")
os.Exit(1)
}

var targetUrl string
if region != "" {
if !slices.Contains(validRegions, region) {
err := fmt.Errorf("region value is '%s', but can be one of %q", region, validRegions)
setupLog.Error(err, "invalid arguments for running operator")
os.Exit(1)
}
targetUrl = regionToGrpcUrl[region]
}

if domain != "" {
targetUrl = fmt.Sprintf("ng-api-grpc.%s:443", domain)
}

if apiKey == "" {
err := fmt.Errorf("api-key can not be empty")
setupLog.Error(err, "invalid arguments for running operator")
Expand Down Expand Up @@ -141,7 +164,6 @@ func main() {
os.Exit(1)
}

targetUrl := regionToGrpcUrl[region]
if err = (&alphacontrollers.RuleGroupReconciler{
CoralogixClientSet: clientset.NewClientSet(targetUrl, apiKey),
Client: mgr.GetClient(),
Expand Down

0 comments on commit 28c8503

Please sign in to comment.