-
Notifications
You must be signed in to change notification settings - Fork 1
/
binding.go
42 lines (37 loc) · 1.16 KB
/
binding.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
package main
// Binding struct binds IngressConfig (user-defined) with an Ingress (Kube resource) and Service (Kube resource)
type Binding struct {
UserConfig
Service
Ingress
}
// GetIPAddress returns the IP address of the service based on the IPType
// A service can either have a clusterIP or externalIP. The method returns approprately
// If the IngressConfig.IPType is anything other than clusterIP or externalIP empty string is returned
func (b Binding) GetIPAddress() string {
switch b.UserConfig.IPType {
case "clusterIP":
return b.Service.Spec.ClusterIP
case "externalIP":
return b.Service.Spec.ExternalIP
default:
return ""
}
}
// GetHosts returns the list of hosts configured in the binding's Ingress resource's rules
func (b Binding) GetHosts() []string {
rules := b.Ingress.Spec.Rules
hosts := make([]string, len(rules))
for i, rule := range rules {
hosts[i] = rule.Host
}
return hosts
}
// GetId returns the name of the user provided ingress configurations
func (b Binding) GetId() string {
return b.UserConfig.Name
}
// GetId returns the name of the user provided ingress configurations
func (b Binding) GetName() string {
return b.UserConfig.Name
}