(feat) Add auto-discovery in k8s | Adarsh

This commit is contained in:
Adarsh K Kumar
2020-10-30 21:00:03 +05:30
parent d76caeeb35
commit 81e6e0b188
1170 changed files with 441034 additions and 14 deletions

34
discovery/discovery.go Normal file
View File

@ -0,0 +1,34 @@
package discovery
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.K8sClusterMode)
services := k8s.GetServices(client, "services")
svcs := make([]*core.Service, 0)
for _, s := range services {
if exclude(cfg.ExcludeSuffix, s.Name) {
continue
}
svc := core.Service{Name: s.Name, URL: fmt.Sprintf("http://%s%s/health", s.Name, cfg.K8SServiceSuffix), Interval: cfg.K8SServiceConfig.Interval, Conditions: cfg.K8SServiceConfig.Conditions}
svcs = append(svcs, &svc)
}
return svcs
}
func exclude(excludeList []string, name string) bool {
for _, x := range excludeList {
if strings.HasSuffix(name, x) {
return true
}
}
return false
}