2019-03-14 14:56:06 +00:00
|
|
|
package ingress
|
|
|
|
|
|
|
|
import (
|
2020-01-16 09:14:06 +00:00
|
|
|
"k8s.io/api/networking/v1beta1"
|
2019-03-14 14:56:06 +00:00
|
|
|
)
|
|
|
|
|
2020-01-16 09:14:06 +00:00
|
|
|
func buildIngress(opts ...func(*v1beta1.Ingress)) *v1beta1.Ingress {
|
|
|
|
i := &v1beta1.Ingress{}
|
2019-03-14 14:56:06 +00:00
|
|
|
i.Kind = "Ingress"
|
|
|
|
for _, opt := range opts {
|
|
|
|
opt(i)
|
|
|
|
}
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
|
2020-01-16 09:14:06 +00:00
|
|
|
func iNamespace(value string) func(*v1beta1.Ingress) {
|
|
|
|
return func(i *v1beta1.Ingress) {
|
2019-03-14 14:56:06 +00:00
|
|
|
i.Namespace = value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-16 09:14:06 +00:00
|
|
|
func iRules(opts ...func(*v1beta1.IngressSpec)) func(*v1beta1.Ingress) {
|
|
|
|
return func(i *v1beta1.Ingress) {
|
|
|
|
s := &v1beta1.IngressSpec{}
|
2019-03-14 14:56:06 +00:00
|
|
|
for _, opt := range opts {
|
|
|
|
opt(s)
|
|
|
|
}
|
|
|
|
i.Spec = *s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-16 09:14:06 +00:00
|
|
|
func iRule(opts ...func(*v1beta1.IngressRule)) func(*v1beta1.IngressSpec) {
|
|
|
|
return func(spec *v1beta1.IngressSpec) {
|
|
|
|
r := &v1beta1.IngressRule{}
|
2019-03-14 14:56:06 +00:00
|
|
|
for _, opt := range opts {
|
|
|
|
opt(r)
|
|
|
|
}
|
|
|
|
spec.Rules = append(spec.Rules, *r)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-16 09:14:06 +00:00
|
|
|
func iHost(name string) func(*v1beta1.IngressRule) {
|
|
|
|
return func(rule *v1beta1.IngressRule) {
|
2019-03-14 14:56:06 +00:00
|
|
|
rule.Host = name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-16 09:14:06 +00:00
|
|
|
func iTLSes(opts ...func(*v1beta1.IngressTLS)) func(*v1beta1.Ingress) {
|
|
|
|
return func(i *v1beta1.Ingress) {
|
2019-03-14 14:56:06 +00:00
|
|
|
for _, opt := range opts {
|
2020-01-16 09:14:06 +00:00
|
|
|
iTLS := v1beta1.IngressTLS{}
|
2019-03-14 14:56:06 +00:00
|
|
|
opt(&iTLS)
|
|
|
|
i.Spec.TLS = append(i.Spec.TLS, iTLS)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-16 09:14:06 +00:00
|
|
|
func iTLS(secret string, hosts ...string) func(*v1beta1.IngressTLS) {
|
|
|
|
return func(i *v1beta1.IngressTLS) {
|
2019-03-14 14:56:06 +00:00
|
|
|
i.SecretName = secret
|
|
|
|
i.Hosts = hosts
|
|
|
|
}
|
|
|
|
}
|