-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
108 lines (99 loc) · 2.46 KB
/
main.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
package main
import (
"context"
"encoding/json"
"log"
"github.com/davecgh/go-spew/spew"
rgclient "github.com/szuecs/routegroup-client"
rgv1 "github.com/szuecs/routegroup-client/apis/zalando.org/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func main() {
cli, err := rgclient.CreateUnified()
if err != nil {
log.Fatalf("Failed to create unified RouteGroup client: %v", err)
}
log.Println("have cli")
// example kubernetes.Interface access
ings, err := cli.NetworkingV1().Ingresses("").List(context.TODO(), metav1.ListOptions{})
if err != nil {
log.Fatalf("Failed to list v1 ingresses: %v", err)
}
for _, ing := range ings.Items {
log.Printf("ing Namespace/Name: %s/%s", ing.Namespace, ing.Name)
}
log.Printf("have ing %d", len(ings.Items))
// example RouteGroups access
l, err := cli.ZalandoV1().RouteGroups("").List(context.TODO(), metav1.ListOptions{})
if err != nil {
log.Printf("Failed to get RouteGroup list: %v", err)
} else {
for _, rg := range l.Items {
log.Printf("rg Namespace/Name: %s/%s", rg.Namespace, rg.Name)
log.Printf("status: %+v", rg.Status)
log.Printf("spec: %+v", rg.Spec)
}
}
// test create
name := "myrg"
namespace := "default"
hostname := "myrg.teapot-e2e.zalan.do"
port := 83
newRg := &rgv1.RouteGroup{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
Spec: rgv1.RouteGroupSpec{
Hosts: []string{hostname},
Backends: []rgv1.RouteGroupBackend{
{
Name: name,
Type: "service",
ServiceName: name,
ServicePort: port,
},
{
Name: "router",
Type: "shunt",
},
},
DefaultBackends: []rgv1.RouteGroupBackendReference{
{
BackendName: name,
Weight: 1,
},
},
Routes: []rgv1.RouteGroupRouteSpec{
{
PathSubtree: "/",
},
{
PathSubtree: "/router-response",
Filters: []string{
`status(418)`,
`inlineContent("I am a teapot")`,
},
Backends: []rgv1.RouteGroupBackendReference{
{
BackendName: "router",
Weight: 1,
},
},
},
},
},
}
b, err := json.Marshal(newRg)
log.Printf("b: %s", string(b))
if err != nil {
log.Fatalf("json marshal failed: %v", err)
}
rg, err := cli.ZalandoV1().RouteGroups(namespace).Create(context.TODO(), newRg, metav1.CreateOptions{})
if err != nil {
spew.Dump(newRg)
log.Fatalf("Failed to create routegroup: %v", err)
}
//spew.Dump(rg)
log.Printf("Created %s/%s", namespace, rg.Name)
}