This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathcluster_configuration.go
63 lines (51 loc) · 1.76 KB
/
cluster_configuration.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package interfaces
import (
"io/ioutil"
"github.com/pkg/errors"
)
// Holds details about a cluster used for workflow execution.
type ClusterConfig struct {
Name string `json:"name"`
Endpoint string `json:"endpoint"`
Auth Auth `json:"auth"`
Enabled bool `json:"enabled"`
}
type Auth struct {
Type string `json:"type"`
TokenPath string `json:"tokenPath"`
CertPath string `json:"certPath"`
}
type ClusterEntity struct {
ID string `json:"id"`
Weight float32 `json:"weight"`
}
func (auth Auth) GetCA() ([]byte, error) {
cert, err := ioutil.ReadFile(auth.CertPath)
if err != nil {
return nil, errors.Wrap(err, "failed to read k8s CA cert from configured path")
}
return cert, nil
}
func (auth Auth) GetToken() (string, error) {
token, err := ioutil.ReadFile(auth.TokenPath)
if err != nil {
return "", errors.Wrap(err, "failed to read k8s bearer token from configured path")
}
return string(token), nil
}
type Clusters struct {
ClusterConfigs []ClusterConfig `json:"clusterConfigs"`
LabelClusterMap map[string][]ClusterEntity `json:"labelClusterMap"`
DefaultExecutionLabel string `json:"defaultExecutionLabel"`
}
//go:generate mockery -name ClusterConfiguration -case=underscore -output=../mocks -case=underscore
// Provides values set in runtime configuration files.
// These files can be changed without requiring a full server restart.
type ClusterConfiguration interface {
// Returns clusters defined in runtime configuration files.
GetClusterConfigs() []ClusterConfig
// Returns label cluster map for routing
GetLabelClusterMap() map[string][]ClusterEntity
// Returns default execution label used as fallback if no execution cluster was explicitly defined.
GetDefaultExecutionLabel() string
}