-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathingress.go
87 lines (74 loc) · 1.98 KB
/
ingress.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package validators
import (
"fmt"
"strings"
"github.com/btoll/validator/lib"
)
type IngressManifest struct {
APIVersion string `json:"apiVersion"`
Kind string `json:"kind"`
Metadata `json:"metadata"`
Spec IngressSpec `json:"spec"`
}
type IngressSpec struct {
Rules []IngressRule `json:"rules,omitempty"`
}
type IngressRule struct {
IngressRuleValue `json:",inline,omitempty"`
}
type IngressRuleValue struct {
HTTP HTTPIngressRuleValue `json:"http,omitempty"`
}
type HTTPIngressRuleValue struct {
Paths []HTTPIngressPath `json:"paths,omitempty"`
}
type HTTPIngressPath struct {
Path string `json:"path,omitempty"`
PathType string `json:"pathType,omitempty"`
Backend IngressBackend `json:"backend,omitempty"`
}
type IngressBackend struct {
Service IngressServiceBackend `json:"service,omitempty"`
}
type IngressServiceBackend struct {
Name string `json:"name,omitempty"`
Port ServiceBackendPort `json:"port,omitempty"`
}
type ServiceBackendPort struct {
Name string `json:"name,omitempty"`
Number int `json:"number,omitempty"`
}
func (m IngressManifest) Write() {
dir := fmt.Sprintf("build/%s/ingress", m.Name)
err := lib.CreateBuildDir(dir)
if err != nil {
fmt.Println("err", err)
}
localFile := fmt.Sprintf("%s/local", dir)
WriteTemplate(localFile, "ingress.tpl", m)
ingress, err := GetIngressClient(m.Name)
if err != nil {
fmt.Println("err", err)
}
// Remove all Rancher `cattle` annotations.
for k := range ingress.Annotations {
if strings.Contains(k, "cattle") {
delete(ingress.Annotations, k)
}
}
// This values are empty in the returned struct.
ingress.APIVersion = "networking.k8s.io/v1"
ingress.Kind = "Ingress"
remoteFile := fmt.Sprintf("%s/remote", dir)
WriteTemplate(remoteFile, "ingress.tpl", ingress)
b, err := Validate(localFile, remoteFile)
if err != nil {
fmt.Println("err", err)
}
if b {
err = RemoveDir(dir, fmt.Sprintf("build/%s", m.Name))
if err != nil {
fmt.Println(err)
}
}
}