forked from kubernetes/ingress-gce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
82 lines (74 loc) · 2.24 KB
/
utils.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
package test
import (
api_v1 "k8s.io/api/core/v1"
extensions "k8s.io/api/extensions/v1beta1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/ingress-gce/pkg/annotations"
backendconfig "k8s.io/ingress-gce/pkg/apis/backendconfig/v1beta1"
"k8s.io/ingress-gce/pkg/utils"
)
var (
BackendPort = intstr.IntOrString{Type: intstr.Int, IntVal: 80}
DefaultBeSvcPort = utils.ServicePort{
ID: utils.ServicePortID{Service: types.NamespacedName{Namespace: "system", Name: "default"}, Port: BackendPort},
NodePort: 30000,
Protocol: annotations.ProtocolHTTP,
}
)
// NewIngress returns an Ingress with the given spec.
func NewIngress(name types.NamespacedName, spec extensions.IngressSpec) *extensions.Ingress {
return &extensions.Ingress{
TypeMeta: meta_v1.TypeMeta{
Kind: "Ingress",
APIVersion: "extensions/v1beta1",
},
ObjectMeta: meta_v1.ObjectMeta{
Name: name.Name,
Namespace: name.Namespace,
},
Spec: spec,
}
}
// NewService returns a Service with the given spec.
func NewService(name types.NamespacedName, spec api_v1.ServiceSpec) *api_v1.Service {
return &api_v1.Service{
TypeMeta: meta_v1.TypeMeta{
Kind: "Service",
APIVersion: "v1",
},
ObjectMeta: meta_v1.ObjectMeta{
Name: name.Name,
Namespace: name.Namespace,
},
Spec: spec,
}
}
// NewBackendConfig returns a BackendConfig with the given spec.
func NewBackendConfig(name types.NamespacedName, spec backendconfig.BackendConfigSpec) *backendconfig.BackendConfig {
return &backendconfig.BackendConfig{
ObjectMeta: meta_v1.ObjectMeta{
Name: name.Name,
Namespace: name.Namespace,
},
Spec: spec,
}
}
// Backend returns an IngressBackend with the given service name/port.
func Backend(name string, port intstr.IntOrString) *extensions.IngressBackend {
return &extensions.IngressBackend{
ServiceName: name,
ServicePort: port,
}
}
// DecodeIngress deserializes an Ingress object.
func DecodeIngress(data []byte) (*extensions.Ingress, error) {
decode := scheme.Codecs.UniversalDeserializer().Decode
obj, _, err := decode(data, nil, nil)
if err != nil {
return nil, err
}
return obj.(*extensions.Ingress), nil
}