traefik/pkg/provider/kubernetes/ingress/builder_ingress_test.go

62 lines
1.2 KiB
Go
Raw Permalink Normal View History

package ingress
2023-04-17 08:56:36 +00:00
import netv1 "k8s.io/api/networking/v1"
2023-04-17 08:56:36 +00:00
func buildIngress(opts ...func(*netv1.Ingress)) *netv1.Ingress {
i := &netv1.Ingress{}
i.Kind = "Ingress"
for _, opt := range opts {
opt(i)
}
return i
}
2023-04-17 08:56:36 +00:00
func iNamespace(value string) func(*netv1.Ingress) {
return func(i *netv1.Ingress) {
i.Namespace = value
}
}
2023-04-17 08:56:36 +00:00
func iRules(opts ...func(*netv1.IngressSpec)) func(*netv1.Ingress) {
return func(i *netv1.Ingress) {
s := &netv1.IngressSpec{}
for _, opt := range opts {
opt(s)
}
i.Spec = *s
}
}
2023-04-17 08:56:36 +00:00
func iRule(opts ...func(*netv1.IngressRule)) func(*netv1.IngressSpec) {
return func(spec *netv1.IngressSpec) {
r := &netv1.IngressRule{}
for _, opt := range opts {
opt(r)
}
spec.Rules = append(spec.Rules, *r)
}
}
2023-04-17 08:56:36 +00:00
func iHost(name string) func(*netv1.IngressRule) {
return func(rule *netv1.IngressRule) {
rule.Host = name
}
}
2023-04-17 08:56:36 +00:00
func iTLSes(opts ...func(*netv1.IngressTLS)) func(*netv1.Ingress) {
return func(i *netv1.Ingress) {
for _, opt := range opts {
2023-04-17 08:56:36 +00:00
iTLS := netv1.IngressTLS{}
opt(&iTLS)
i.Spec.TLS = append(i.Spec.TLS, iTLS)
}
}
}
2023-04-17 08:56:36 +00:00
func iTLS(secret string, hosts ...string) func(*netv1.IngressTLS) {
return func(i *netv1.IngressTLS) {
i.SecretName = secret
i.Hosts = hosts
}
}