forked from kedacore/http-add-on
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhosts.go
38 lines (32 loc) · 939 Bytes
/
hosts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"fmt"
"strings"
"github.com/go-logr/logr"
"github.com/kedacore/http-add-on/pkg/routing"
externalscaler "github.com/kedacore/http-add-on/proto"
)
// getHostCount gets proper count for given host regardless whether
// host is in counts or only in routerTable
func getHostCount(
host string,
counts map[string]int,
table routing.TableReader,
) (int, bool) {
count, exists := counts[host]
if exists {
return count, exists
}
exists = table.HasHost(host)
return 0, exists
}
// gets hosts from scaledobjectref
func getHostsFromScaledObjectRef(lggr logr.Logger, sor *externalscaler.ScaledObjectRef) ([]string, error) {
serializedHosts, ok := sor.ScalerMetadata["hosts"]
if !ok {
err := fmt.Errorf("no 'hosts' field in the scaler metadata field")
lggr.Error(err, "'hosts' not found in the scaler metadata field")
return make([]string, 0), err
}
return strings.Split(serializedHosts, ","), nil
}