forked from Harwayne/knative-gcp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
broker_lifecycle.go
107 lines (86 loc) · 3.89 KB
/
broker_lifecycle.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
/*
Copyright 2020 Google LLC
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 (
eventingv1beta1 "knative.dev/eventing/pkg/apis/eventing/v1beta1"
"knative.dev/pkg/apis"
)
var brokerCondSet = apis.NewLivingConditionSet(
eventingv1beta1.BrokerConditionAddressable,
BrokerConditionBrokerCell,
BrokerConditionTopic,
BrokerConditionSubscription,
)
const (
// BrokerConditionBrokerCell reports the availability of the Broker's BrokerCell.
BrokerConditionBrokerCell apis.ConditionType = "BrokerCellReady"
// BrokerConditionTopic reports the status of the Broker's PubSub topic.
// THis condition is specific to the Google Cloud Broker.
BrokerConditionTopic apis.ConditionType = "TopicReady"
// BrokerConditionSubscription reports the status of the Broker's PubSub
// subscription. This condition is specific to the Google Cloud Broker.
BrokerConditionSubscription apis.ConditionType = "SubscriptionReady"
)
// GetCondition returns the condition currently associated with the given type, or nil.
func (bs *BrokerStatus) GetCondition(t apis.ConditionType) *apis.Condition {
return brokerCondSet.Manage(bs).GetCondition(t)
}
// GetTopLevelCondition returns the top level Condition.
func (bs *BrokerStatus) GetTopLevelCondition() *apis.Condition {
return brokerCondSet.Manage(bs).GetTopLevelCondition()
}
// IsReady returns true if the resource is ready overall.
func (bs *BrokerStatus) IsReady() bool {
return brokerCondSet.Manage(bs).IsHappy()
}
// InitializeConditions sets relevant unset conditions to Unknown state.
func (bs *BrokerStatus) InitializeConditions() {
brokerCondSet.Manage(bs).InitializeConditions()
}
// SetAddress makes this Broker addressable by setting the hostname. It also
// sets the BrokerConditionAddressable to true.
func (bs *BrokerStatus) SetAddress(url *apis.URL) {
bs.Address.URL = url
if url != nil {
brokerCondSet.Manage(bs).MarkTrue(eventingv1beta1.BrokerConditionAddressable)
} else {
brokerCondSet.Manage(bs).MarkFalse(eventingv1beta1.BrokerConditionAddressable, "emptyURL", "URL is empty")
}
}
func (bs *BrokerStatus) MarkBrokerCellUnknown(reason, format string, args ...interface{}) {
brokerCondSet.Manage(bs).MarkUnknown(BrokerConditionBrokerCell, reason, format, args...)
}
func (bs *BrokerStatus) MarkBrokerCellFailed(reason, format string, args ...interface{}) {
brokerCondSet.Manage(bs).MarkFalse(BrokerConditionBrokerCell, reason, format, args...)
}
func (bs *BrokerStatus) MarkBrokerCellReady() {
brokerCondSet.Manage(bs).MarkTrue(BrokerConditionBrokerCell)
}
func (bs *BrokerStatus) MarkTopicFailed(reason, format string, args ...interface{}) {
brokerCondSet.Manage(bs).MarkFalse(BrokerConditionTopic, reason, format, args...)
}
func (bs *BrokerStatus) MarkTopicUnknown(reason, format string, args ...interface{}) {
brokerCondSet.Manage(bs).MarkUnknown(BrokerConditionTopic, reason, format, args...)
}
func (bs *BrokerStatus) MarkTopicReady() {
brokerCondSet.Manage(bs).MarkTrue(BrokerConditionTopic)
}
func (bs *BrokerStatus) MarkSubscriptionFailed(reason, format string, args ...interface{}) {
brokerCondSet.Manage(bs).MarkFalse(BrokerConditionSubscription, reason, format, args...)
}
func (bs *BrokerStatus) MarkSubscriptionUnknown(reason, format string, args ...interface{}) {
brokerCondSet.Manage(bs).MarkUnknown(BrokerConditionSubscription, reason, format, args...)
}
func (bs *BrokerStatus) MarkSubscriptionReady() {
brokerCondSet.Manage(bs).MarkTrue(BrokerConditionSubscription)
}