Fix canary config manager creation error in controller (#1105)
Fixing failure of the controller startup when Prometheus is provided as env variable and it fails to parse correctly
This commit is contained in:
@@ -19,6 +19,7 @@ package canaryconfigmgr
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -47,19 +48,29 @@ type canaryConfigMgr struct {
|
|||||||
|
|
||||||
func MakeCanaryConfigMgr(fissionClient *crd.FissionClient, kubeClient *kubernetes.Clientset, crdClient *rest.RESTClient, prometheusSvc string) (*canaryConfigMgr, error) {
|
func MakeCanaryConfigMgr(fissionClient *crd.FissionClient, kubeClient *kubernetes.Clientset, crdClient *rest.RESTClient, prometheusSvc string) (*canaryConfigMgr, error) {
|
||||||
if prometheusSvc == "" {
|
if prometheusSvc == "" {
|
||||||
|
log.Info("Try to retrieve prometheus server information from environment variables")
|
||||||
|
|
||||||
|
var prometheusSvcHost, prometheusSvcPort string
|
||||||
// handle a case where there is a prometheus server is already installed, try to find the service from env variable
|
// handle a case where there is a prometheus server is already installed, try to find the service from env variable
|
||||||
envVars := os.Environ()
|
envVars := os.Environ()
|
||||||
|
|
||||||
for _, envVar := range envVars {
|
for _, envVar := range envVars {
|
||||||
if strings.Contains(envVar, "PROMETHEUS_SERVER_SERVICE_HOST") {
|
if strings.Contains(envVar, "PROMETHEUS_SERVER_SERVICE_HOST") {
|
||||||
envVarSplit := strings.Split(envVar, "=")
|
prometheusSvcHost = getEnvValue(envVar)
|
||||||
prometheusSvc = envVarSplit[1]
|
} else if strings.Contains(envVar, "PROMETHEUS_SERVER_SERVICE_PORT") {
|
||||||
|
prometheusSvcPort = getEnvValue(envVar)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(prometheusSvcHost) > 0 && len(prometheusSvcPort) > 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
prometheusSvc = fmt.Sprintf("http://%v:%v", prometheusSvcHost, prometheusSvcPort)
|
||||||
|
}
|
||||||
|
|
||||||
if prometheusSvc == "" {
|
_, err := url.Parse(prometheusSvc)
|
||||||
return nil, fmt.Errorf("prometheus service not found, cant create canary config manager")
|
if err != nil {
|
||||||
}
|
return nil, fmt.Errorf("prometheus service url not found/invalid, cant create canary config manager: %v", prometheusSvc)
|
||||||
}
|
}
|
||||||
|
|
||||||
promClient, err := MakePrometheusClient(prometheusSvc)
|
promClient, err := MakePrometheusClient(prometheusSvc)
|
||||||
@@ -390,3 +401,8 @@ func (canaryCfgMgr *canaryConfigMgr) updateCanaryConfig(oldCanaryConfig *crd.Can
|
|||||||
}
|
}
|
||||||
canaryCfgMgr.addCanaryConfig(newCanaryConfig)
|
canaryCfgMgr.addCanaryConfig(newCanaryConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getEnvValue(envVar string) string {
|
||||||
|
envVarSplit := strings.Split(envVar, "=")
|
||||||
|
return envVarSplit[1]
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user