/
testutility.go
127 lines (116 loc) · 2.91 KB
/
testutility.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
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
package store
import (
ingressv1alpha1 "github.com/ngrok/kubernetes-ingress-controller/api/ingress/v1alpha1"
corev1 "k8s.io/api/core/v1"
netv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)
func NewTestIngressClass(name string, isDefault bool, isNgrok bool) netv1.IngressClass {
i := netv1.IngressClass{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Labels: map[string]string{
"app.kubernetes.io/component": "controller",
},
},
}
if isNgrok {
i.Spec.Controller = "k8s.ngrok.com/ingress-controller"
} else {
i.Spec.Controller = "kubernetes.io/ingress-other"
}
if isDefault {
i.Annotations = map[string]string{
"ingressclass.kubernetes.io/is-default-class": "true", // TODO: Move this into a utility for ingress classes
}
}
return i
}
func NewTestIngressV1WithClass(name string, namespace string, ingressClass string) netv1.Ingress {
i := NewTestIngressV1(name, namespace)
i.Spec.IngressClassName = &ingressClass
return i
}
func NewTestIngressV1(name string, namespace string) netv1.Ingress {
return netv1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
Spec: netv1.IngressSpec{
Rules: []netv1.IngressRule{
{
Host: "example.com",
IngressRuleValue: netv1.IngressRuleValue{
HTTP: &netv1.HTTPIngressRuleValue{
Paths: []netv1.HTTPIngressPath{
{
Path: "/",
Backend: netv1.IngressBackend{
Service: &netv1.IngressServiceBackend{
Name: "example",
Port: netv1.ServiceBackendPort{
Number: 80,
},
},
},
},
},
},
},
},
},
},
}
}
func NewTestServiceV1(name string, namespace string) corev1.Service {
return corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{
{
Name: "http",
Protocol: "TCP",
Port: 80,
TargetPort: intstr.FromString("http"),
},
},
},
}
}
func NewDomainV1(name string, namespace string) ingressv1alpha1.Domain {
return ingressv1alpha1.Domain{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
Spec: ingressv1alpha1.DomainSpec{
Domain: name,
},
}
}
func NewHTTPSEdge(name string, namespace string, domain string) ingressv1alpha1.HTTPSEdge {
return ingressv1alpha1.HTTPSEdge{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
}
}
func NewTestNgrokModuleSet(name string, namespace string, compressionEnabled bool) ingressv1alpha1.NgrokModuleSet {
return ingressv1alpha1.NgrokModuleSet{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
Modules: ingressv1alpha1.NgrokModuleSetModules{
Compression: &ingressv1alpha1.EndpointCompression{
Enabled: compressionEnabled,
},
},
}
}