mirror of
https://github.com/TwiN/gatus.git
synced 2024-11-21 23:43:27 +01:00
Move discovery configuration validation in config package
This commit is contained in:
parent
559d286121
commit
42659a0878
@ -9,6 +9,7 @@ import (
|
||||
"github.com/TwinProduction/gatus/alerting"
|
||||
"github.com/TwinProduction/gatus/alerting/provider"
|
||||
"github.com/TwinProduction/gatus/core"
|
||||
"github.com/TwinProduction/gatus/discovery"
|
||||
"github.com/TwinProduction/gatus/k8s"
|
||||
"github.com/TwinProduction/gatus/security"
|
||||
"gopkg.in/yaml.v2"
|
||||
@ -123,10 +124,18 @@ func parseAndValidateConfigBytes(yamlBytes []byte) (config *Config, err error) {
|
||||
validateAlertingConfig(config)
|
||||
validateSecurityConfig(config)
|
||||
validateServicesConfig(config)
|
||||
validateKubernetesConfig(config)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func validateKubernetesConfig(config *Config) {
|
||||
if config.Kubernetes != nil && config.Kubernetes.AutoDiscover {
|
||||
discoveredServices := discovery.GetServices(config.Kubernetes)
|
||||
config.Services = append(config.Services, discoveredServices...)
|
||||
}
|
||||
}
|
||||
|
||||
func validateServicesConfig(config *Config) {
|
||||
for _, service := range config.Services {
|
||||
if config.Debug {
|
||||
|
@ -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)
|
||||
}
|
||||
|
5
main.go
5
main.go
@ -10,7 +10,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/TwinProduction/gatus/config"
|
||||
"github.com/TwinProduction/gatus/discovery"
|
||||
"github.com/TwinProduction/gatus/security"
|
||||
"github.com/TwinProduction/gatus/watchdog"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
@ -26,10 +25,6 @@ var (
|
||||
|
||||
func main() {
|
||||
cfg := loadConfiguration()
|
||||
if cfg.Kubernetes.AutoDiscover {
|
||||
discoveredServices := discovery.GetServices(cfg)
|
||||
cfg.Services = append(cfg.Services, discoveredServices...)
|
||||
}
|
||||
resultsHandler := serviceResultsHandler
|
||||
if cfg.Security != nil && cfg.Security.IsValid() {
|
||||
resultsHandler = security.Handler(serviceResultsHandler, cfg.Security)
|
||||
|
Loading…
Reference in New Issue
Block a user