/
subscribable_types.go
162 lines (138 loc) · 5.37 KB
/
subscribable_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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
Copyright 2020 The Knative Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v1beta1
import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"knative.dev/pkg/apis"
"knative.dev/pkg/apis/duck"
)
// +genduck
var _ duck.Implementable = (*Subscribable)(nil)
// SubscriberSpec defines a single subscriber to a Subscribable.
//
// At least one of SubscriberURI and ReplyURI must be present
type SubscriberSpec struct {
// UID is used to understand the origin of the subscriber.
// +optional
UID types.UID `json:"uid,omitempty"`
// Generation of the origin of the subscriber with uid:UID.
// +optional
Generation int64 `json:"generation,omitempty"`
// SubscriberURI is the endpoint for the subscriber
// +optional
SubscriberURI *apis.URL `json:"subscriberUri,omitempty"`
// ReplyURI is the endpoint for the reply
// +optional
ReplyURI *apis.URL `json:"replyUri,omitempty"`
// +optional
// DeliverySpec contains options controlling the event delivery
// +optional
Delivery *DeliverySpec `json:"delivery,omitempty"`
}
// SubscriberStatus defines the status of a single subscriber to a Channel.
type SubscriberStatus struct {
// UID is used to understand the origin of the subscriber.
// +optional
UID types.UID `json:"uid,omitempty"`
// Generation of the origin of the subscriber with uid:UID.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
// Status of the subscriber.
Ready corev1.ConditionStatus `json:"ready,omitempty"`
// A human readable message indicating details of Ready status.
// +optional
Message string `json:"message,omitempty"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// Subscribable is a skeleton type wrapping Subscribable in the manner we expect resource writers
// defining compatible resources to embed it. We will typically use this type to deserialize
// SubscribableType ObjectReferences and access the Subscription data. This is not a real resource.
type Subscribable struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
// SubscribableSpec is the part where Subscribable object is
// configured as to be compatible with Subscribable contract.
Spec SubscribableSpec `json:"spec"`
// SubscribableStatus is the part where SubscribableStatus object is
// configured as to be compatible with Subscribable contract.
Status SubscribableStatus `json:"status"`
}
// SubscribableSpec shows how we expect folks to embed Subscribable in their Spec field.
type SubscribableSpec struct {
// This is the list of subscriptions for this subscribable.
// +patchMergeKey=uid
// +patchStrategy=merge
Subscribers []SubscriberSpec `json:"subscribers,omitempty" patchStrategy:"merge" patchMergeKey:"uid"`
}
// SubscribableStatus is the schema for the subscribable's status portion of the status
// section of the resource.
type SubscribableStatus struct {
// This is the list of subscription's statuses for this channel.
// +patchMergeKey=uid
// +patchStrategy=merge
Subscribers []SubscriberStatus `json:"subscribers,omitempty" patchStrategy:"merge" patchMergeKey:"uid"`
}
var (
// Verify SubscribableType resources meet duck contracts.
_ duck.Populatable = (*Subscribable)(nil)
_ apis.Listable = (*Subscribable)(nil)
_ apis.Convertible = (*Subscribable)(nil)
_ apis.Convertible = (*SubscribableSpec)(nil)
_ apis.Convertible = (*SubscribableStatus)(nil)
_ apis.Convertible = (*SubscriberSpec)(nil)
_ apis.Convertible = (*SubscriberStatus)(nil)
)
// GetFullType implements duck.Implementable
func (s *Subscribable) GetFullType() duck.Populatable {
return &Subscribable{}
}
// Populate implements duck.Populatable
func (c *Subscribable) Populate() {
c.Spec.Subscribers = []SubscriberSpec{{
UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1",
Generation: 1,
SubscriberURI: apis.HTTP("call1"),
ReplyURI: apis.HTTP("sink2"),
}, {
UID: "34c5aec8-deb6-11e8-9f32-f2801f1b9fd1",
Generation: 2,
SubscriberURI: apis.HTTP("call2"),
ReplyURI: apis.HTTP("sink2"),
}}
c.Status.Subscribers = // Populate ALL fields
[]SubscriberStatus{{
UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1",
ObservedGeneration: 1,
Ready: corev1.ConditionTrue,
Message: "Some message",
}, {
UID: "34c5aec8-deb6-11e8-9f32-f2801f1b9fd1",
ObservedGeneration: 2,
Ready: corev1.ConditionFalse,
Message: "Some message",
}}
}
// GetListType implements apis.Listable
func (c *Subscribable) GetListType() runtime.Object {
return &SubscribableList{}
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// SubscribableTypeList is a list of SubscribableType resources
type SubscribableList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []Subscribable `json:"items"`
}