forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ingress_common.go
38 lines (33 loc) · 919 Bytes
/
ingress_common.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 ingress
import (
"encoding/base64"
"encoding/json"
"fmt"
"strings"
"github.com/rancher/norman/types/convert"
"github.com/rancher/rancher/pkg/settings"
"k8s.io/api/extensions/v1beta1"
)
const (
ingressStateAnnotation = "field.cattle.io/ingressState"
)
func GetStateKey(name, namespace, host string, path string, port string) string {
ipDomain := settings.IngressIPDomain.Get()
if ipDomain != "" && strings.HasSuffix(host, ipDomain) {
host = ipDomain
}
key := fmt.Sprintf("%s/%s/%s/%s/%s", name, namespace, host, path, port)
return base64.URLEncoding.EncodeToString([]byte(key))
}
func GetIngressState(obj *v1beta1.Ingress) map[string]string {
annotations := obj.Annotations
if annotations == nil {
return nil
}
if v, ok := annotations[ingressStateAnnotation]; ok {
state := make(map[string]string)
json.Unmarshal([]byte(convert.ToString(v)), &state)
return state
}
return nil
}