Move discovery configuration validation in config package

This commit is contained in:
TwinProduction
2020-11-11 14:22:31 -05:00
parent 559d286121
commit 42659a0878
3 changed files with 17 additions and 14 deletions

View File

@ -4,27 +4,26 @@ import (
"fmt"
"strings"
"github.com/TwinProduction/gatus/config"
"github.com/TwinProduction/gatus/core"
"github.com/TwinProduction/gatus/k8s"
)
//GetServices return discovered service
func GetServices(cfg *config.Config) []*core.Service {
client := k8s.NewClient(cfg.Kubernetes.ClusterMode)
func GetServices(kubernetesConfig *k8s.Config) []*core.Service {
client := k8s.NewClient(kubernetesConfig.ClusterMode)
svcs := make([]*core.Service, 0)
for _, ns := range cfg.Kubernetes.Namespaces {
for _, ns := range kubernetesConfig.Namespaces {
services := k8s.GetServices(client, ns.Name)
for _, s := range services {
if exclude(cfg.Kubernetes.ExcludeSuffix, s.Name) {
if exclude(kubernetesConfig.ExcludeSuffix, s.Name) {
continue
}
svc := core.Service{Name: s.Name,
svc := core.Service{
Name: s.Name,
URL: fmt.Sprintf("http://%s%s/%s", s.Name, ns.ServiceSuffix, ns.HealthAPI),
Interval: cfg.Kubernetes.ServiceTemplate.Interval,
Conditions: cfg.Kubernetes.ServiceTemplate.Conditions,
Interval: kubernetesConfig.ServiceTemplate.Interval,
Conditions: kubernetesConfig.ServiceTemplate.Conditions,
}
svcs = append(svcs, &svc)
}