-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathingress.nu
executable file
·129 lines (90 loc) · 3.17 KB
/
ingress.nu
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env nu
def "main apply ingress" [
type = "traefik" # The type of Ingress controller to apply. Available options: traefik, contour, nginx
--hyperscaler = ""
--env_prefix = ""
] {
if $type == "traefik" {
(
helm upgrade --install traefik traefik
--repo https://helm.traefik.io/traefik
--namespace traefik --create-namespace --wait
)
} else if $type == "contour" {
(
helm upgrade --install contour
oci://registry-1.docker.io/bitnamicharts/contour
--namespace contour --create-namespace --wait
)
} else if $type == "nginx" {
if $hyperscaler == "kind" {
(
kubectl apply
--filename https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml
)
sleep 10sec
(
kubectl --namespace ingress-nginx wait
--for=condition=Available
deployment ingress-nginx-controller
)
sleep 5sec
(
kubectl --namespace ingress-nginx wait
--for=condition=Complete
job ingress-nginx-admission-create
)
(
kubectl --namespace ingress-nginx wait
--for=condition=Complete
job ingress-nginx-admission-patch
)
}
} else {
print $"(ansi red_bold)($type)(ansi reset) is not a supported."
exit 1
}
main get ingress $type --hyperscaler $hyperscaler --env_prefix $env_prefix
}
def "main get ingress" [
type = "traefik" # The type of Ingress controller to apply. Available options: traefik, contour, nginx
--hyperscaler: string
--env_prefix = ""
] {
mut service_name = $type
if $type == "contour" {
$service_name = "contour-envoy"
}
mut ingress_ip = ""
if $hyperscaler == "aws" {
sleep 30sec
let ingress_hostname = (
kubectl --namespace $type
get service $service_name --output yaml
| from yaml
| get status.loadBalancer.ingress.0.hostname
)
while $ingress_ip == "" {
print "Waiting for Ingress Service IP..."
sleep 10sec
$ingress_ip = (dig +short $ingress_hostname)
}
$ingress_ip = $ingress_ip | lines | first
} else if $hyperscaler == "kind" {
$ingress_ip = "127.0.0.1"
} else {
while $ingress_ip == "" {
print "Waiting for Ingress Service IP..."
sleep 10sec
$ingress_ip = (
kubectl --namespace $type
get service $service_name --output yaml
| from yaml
| get status.loadBalancer.ingress.0.ip
)
}
}
$"export ($env_prefix)INGRESS_IP=($ingress_ip)\n" | save --append .env
$"export ($env_prefix)INGRESS_HOST=($ingress_ip).nip.io\n" | save --append .env
{ip: $ingress_ip, host: $"($ingress_ip).nip.io", class: $type}
}