/
types.go
114 lines (99 loc) · 3.73 KB
/
types.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
package gatewayapi
import (
"encoding/json"
"k8s.io/client-go/pkg/api"
"k8s.io/client-go/pkg/api/meta"
"k8s.io/client-go/pkg/api/unversioned"
)
// GatewayApi provides the type for an
// API plugin resource in Kubernetes.
type GatewayApi struct {
unversioned.TypeMeta `json:",inline"`
Metadata api.ObjectMeta `json:"metadata"`
Spec Spec `json:"spec"`
}
// Event provides the event recieved for gateway api resource watchers.
type Event struct {
Type string `json:"type"`
Object GatewayApi `json:"object"`
}
// UpdateEvent provides the event recieved for gateway api resource watchers
// for update events specifically.
type UpdateEvent struct {
Old GatewayApi `json:"old"`
New GatewayApi `json:"new"`
}
// GetObjectKind provides the method to expose the kind
// of our GatewayApi object.
func (p *GatewayApi) GetObjectKind() unversioned.ObjectKind {
return &p.TypeMeta
}
// GetObjectMeta Retrieves the metadata for the GatewayApi.
func (p *GatewayApi) GetObjectMeta() meta.Object {
return &p.Metadata
}
// GACopy provides an alias of the GatewayApi to be utilised
// in unmarshalling of JSON data.
type GACopy GatewayApi
// UnmarshalJSON provides the way in which JSON should be unmarshalled correctly for this type.
// This is a temporary workaround for https://github.com/kubernetes/client-go/issues/8
func (p *GatewayApi) UnmarshalJSON(data []byte) error {
tmp := GACopy{}
err := json.Unmarshal(data, &tmp)
if err != nil {
return err
}
tmp2 := GatewayApi(tmp)
*p = tmp2
return nil
}
// GatewayApiList provides the type encapsulating a list of GatewayApi resources.
type GatewayApiList struct {
unversioned.TypeMeta `json:",inline"`
Metadata unversioned.ListMeta `json:"metadata"`
Items []GatewayApi `json:"items"`
}
// GetObjectKind provides the method to expose the kind
// of our GatewayApi List object.
func (l *GatewayApiList) GetObjectKind() unversioned.ObjectKind {
return &l.TypeMeta
}
// GetListMeta Retrieves the metadata for the GatewayApi List.
func (l *GatewayApiList) GetListMeta() unversioned.List {
return &l.Metadata
}
// ListCopy provides the type alias for list to be used in unmarshalling from JSON.
type ListCopy GatewayApiList
// UnmarshalJSON provides the way in which JSON should be unmarshalled correctly for this list type.
// Temporary workaround for https://github.com/kubernetes/client-go/issues/8
func (l *GatewayApiList) UnmarshalJSON(data []byte) error {
tmp := ListCopy{}
err := json.Unmarshal(data, &tmp)
if err != nil {
return err
}
tmp2 := GatewayApiList(tmp)
*l = tmp2
return nil
}
// Spec provides the type for the specification
// of the plugin resource specification.
// The name and upstream url of the API to be created in kong are
// taken from the service in the selector.
type Spec struct {
Hosts []string `json:"hosts,omitempty"`
Uris []string `json:"uris,omitempty"`
StripURI *bool `json:"strip_uri,omitempty"`
Methods []string `json:"methods,omitempty"`
PreserveHost *bool `json:"preserve_host,omitempty"`
Retries int64 `json:"retries,omitempty"`
UpstreamConnectTimeout int64 `json:"upstream_connect_timeout,omitempty"`
UpstreamSendTimeout int64 `json:"upstream_send_timeout,omitempty"`
UpstreamReadTimeout int64 `json:"upstream_read_timeout,omitempty"`
HTTPSOnly *bool `json:"https_only,omitempty"`
HTTPIfTerminated *bool `json:"http_if_terminated,omitempty"`
// Label selector for selecting the services the GatewayApi resource
// represents. This will then create a new API object
// in Kong for the configuration and service upstream host.
Selector map[string]string `json:"selector"`
}