Skip to content

Commit 562510b

Browse files
authored
Support custom domain (#157)
1 parent 9b4fd66 commit 562510b

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Add the region and api-key as environment variables (or later as flags).
3636
$ export CORALOGIX_API_KEY="xxx-xxx-xxx"
3737
$ export CORALOGIX_REGION = "EU2"
3838
```
39+
For private domain the `domain` field or the environment variable `CORALOGIX_DOMAIN` have to be defined.
3940

4041
Run the operator locally
4142
```sh

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ make install
3434
$ export CORALOGIX_API_KEY="<api-key>"
3535
$ export CORALOGIX_REGION="<region>"
3636
```
37+
For private domain the `domain` field or the environment variable `CORALOGIX_DOMAIN` have to be defined.
3738

3839
3. Build and push your image to the location specified by `IMG`:
3940
```sh

main.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,13 @@ func main() {
8787
"Enabling this will ensure there is only one active controller manager.")
8888

8989
region := os.Getenv("CORALOGIX_REGION")
90-
flag.StringVar(&region, "region", region, fmt.Sprintf("The region of your Coralogix cluster. Can be one of %q.", validRegions))
90+
flag.StringVar(&region, "region", region, fmt.Sprintf("The region of your Coralogix cluster. Can be one of %q. Conflicts with 'domain'.", validRegions))
91+
92+
domain := os.Getenv("CORALOGIX_DOMAIN")
93+
flag.StringVar(&domain, "domain", domain, "The domain of your Coralogix cluster. Conflicts with 'region'.")
9194

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

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

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

107-
if !slices.Contains(validRegions, region) {
108-
err := fmt.Errorf("region value is '%s', but can be one of %q", region, validRegions)
110+
if region != "" && domain != "" {
111+
err := fmt.Errorf("region and domain flags are mutually exclusive")
112+
setupLog.Error(err, "invalid arguments for running operator")
113+
os.Exit(1)
114+
}
115+
116+
if region == "" && domain == "" {
117+
err := fmt.Errorf("region or domain must be set")
109118
setupLog.Error(err, "invalid arguments for running operator")
110119
os.Exit(1)
111120
}
112121

122+
var targetUrl string
123+
if region != "" {
124+
if !slices.Contains(validRegions, region) {
125+
err := fmt.Errorf("region value is '%s', but can be one of %q", region, validRegions)
126+
setupLog.Error(err, "invalid arguments for running operator")
127+
os.Exit(1)
128+
}
129+
targetUrl = regionToGrpcUrl[region]
130+
} else if domain != "" {
131+
targetUrl = fmt.Sprintf("ng-api-grpc.%s:443", domain)
132+
}
133+
113134
if apiKey == "" {
114135
err := fmt.Errorf("api-key can not be empty")
115136
setupLog.Error(err, "invalid arguments for running operator")
@@ -141,7 +162,6 @@ func main() {
141162
os.Exit(1)
142163
}
143164

144-
targetUrl := regionToGrpcUrl[region]
145165
if err = (&alphacontrollers.RuleGroupReconciler{
146166
CoralogixClientSet: clientset.NewClientSet(targetUrl, apiKey),
147167
Client: mgr.GetClient(),

0 commit comments

Comments
 (0)