forked from openshift/origin
/
types.go
61 lines (53 loc) · 2.35 KB
/
types.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
package templaterouter
import (
routeapi "github.com/openshift/origin/pkg/route/api"
"strings"
)
// ServiceUnit is an encapsulation of a service, the endpoints that back that service, and the routes
// that point to the service. This is the data that drives the creation of the router configuration files
type ServiceUnit struct {
// Name corresponds to a service name & namespace. Uniquely identifies the ServiceUnit
Name string
// EndpointTable are endpoints that back the service, this translates into a final backend implementation for routers
// keyed by IP:port for easy access
EndpointTable map[string]Endpoint
// ServiceAliasConfigs is a collection of unique routes that support this service, keyed by host + path
ServiceAliasConfigs map[string]ServiceAliasConfig
}
// ServiceAliasConfig is a route for a service. Uniquely identified by host + path.
type ServiceAliasConfig struct {
// Host is a required host name ie. www.example.com
Host string
// Path is an optional path ie. www.example.com/myservice where "myservice" is the path
Path string
// TLSTermination is the termination policy for this backend and drives the mapping files and router configuration
TLSTermination routeapi.TLSTerminationType
// Certificates used for securing this backend. Keyed by the cert id
Certificates map[string]Certificate
}
// Certificate represents a pub/private key pair. It is identified by ID which is set to indicate if this is
// a client or ca certificate (see router.go). A CA certificate will not have a PrivateKey set.
type Certificate struct {
ID string
Contents string
PrivateKey string
}
// Endpoint is an internal representation of a k8s endpoint.
type Endpoint struct {
ID string
IP string
Port string
}
//TemplateSafeName provides a name that can be used in the template that does not contain restricted
//characters like / which is used to concat namespace and name in the service unit key
func (s ServiceUnit) TemplateSafeName() string {
return templateSafeString(s.Name)
}
//TemplateSafePath provides a name that can be used in the template that does not contain restricted
//characters like / which is used to concat namespace and name in the service unit key
func (s ServiceAliasConfig) TemplateSafePath() string {
return templateSafeString(s.Path)
}
func templateSafeString(s string) string {
return strings.Replace(s, "/", "-", -1)
}