Merge discovery package into k8s package
This commit is contained in:
42
k8s/discovery.go
Normal file
42
k8s/discovery.go
Normal file
@ -0,0 +1,42 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/TwinProduction/gatus/core"
|
||||
)
|
||||
|
||||
// DiscoverServices return discovered services
|
||||
func DiscoverServices(kubernetesConfig *Config) ([]*core.Service, error) {
|
||||
client := NewClient(kubernetesConfig.ClusterMode)
|
||||
services := make([]*core.Service, 0)
|
||||
for _, ns := range kubernetesConfig.Namespaces {
|
||||
kubernetesServices, err := GetKubernetesServices(client, ns.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, s := range kubernetesServices {
|
||||
if isExcluded(kubernetesConfig.ExcludeSuffix, s.Name) {
|
||||
continue
|
||||
}
|
||||
services = append(services, &core.Service{
|
||||
Name: s.Name,
|
||||
URL: fmt.Sprintf("http://%s%s/%s", s.Name, ns.ServiceSuffix, ns.HealthAPI),
|
||||
Interval: kubernetesConfig.ServiceTemplate.Interval,
|
||||
Conditions: kubernetesConfig.ServiceTemplate.Conditions,
|
||||
})
|
||||
}
|
||||
}
|
||||
return services, nil
|
||||
}
|
||||
|
||||
// TODO: don't uselessly allocate new things here, just move this inside the DiscoverServices function
|
||||
func isExcluded(excludeList []string, name string) bool {
|
||||
for _, x := range excludeList {
|
||||
if strings.HasSuffix(name, x) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
Reference in New Issue
Block a user