/
subscription_lifecycle.go
115 lines (91 loc) · 5 KB
/
subscription_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
108
109
110
111
112
113
114
115
/*
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 v1
import (
"knative.dev/pkg/apis"
)
// SubCondSet is a condition set with Ready as the happy condition and
// ReferencesResolved and ChannelReady as the dependent conditions.
var SubCondSet = apis.NewLivingConditionSet(SubscriptionConditionReferencesResolved, SubscriptionConditionAddedToChannel, SubscriptionConditionChannelReady)
const (
// SubscriptionConditionReady has status True when all subconditions below have been set to True.
SubscriptionConditionReady = apis.ConditionReady
// SubscriptionConditionReferencesResolved has status True when all the specified references have been successfully
// resolved.
SubscriptionConditionReferencesResolved apis.ConditionType = "ReferencesResolved"
// SubscriptionConditionAddedToChannel has status True when controller has successfully added a
// subscription to the spec.channel resource.
SubscriptionConditionAddedToChannel apis.ConditionType = "AddedToChannel"
// SubscriptionConditionChannelReady has status True when the channel has marked the subscriber as 'ready'
SubscriptionConditionChannelReady apis.ConditionType = "ChannelReady"
)
// GetConditionSet retrieves the condition set for this resource. Implements the KRShaped interface.
func (*Subscription) GetConditionSet() apis.ConditionSet {
return SubCondSet
}
// GetCondition returns the condition currently associated with the given type, or nil.
func (ss *SubscriptionStatus) GetCondition(t apis.ConditionType) *apis.Condition {
return SubCondSet.Manage(ss).GetCondition(t)
}
// GetTopLevelCondition returns the top level Condition.
func (ss *SubscriptionStatus) GetTopLevelCondition() *apis.Condition {
return SubCondSet.Manage(ss).GetTopLevelCondition()
}
// IsReady returns true if the resource is ready overall.
func (ss *SubscriptionStatus) IsReady() bool {
return SubCondSet.Manage(ss).IsHappy()
}
// IsAddedToChannel returns true if SubscriptionConditionAddedToChannel is true
func (ss *SubscriptionStatus) IsAddedToChannel() bool {
return ss.GetCondition(SubscriptionConditionAddedToChannel).IsTrue()
}
// AreReferencesResolved returns true if SubscriptionConditionReferencesResolved is true
func (ss *SubscriptionStatus) AreReferencesResolved() bool {
return ss.GetCondition(SubscriptionConditionReferencesResolved).IsTrue()
}
// InitializeConditions sets relevant unset conditions to Unknown state.
func (ss *SubscriptionStatus) InitializeConditions() {
SubCondSet.Manage(ss).InitializeConditions()
}
// MarkReferencesResolved sets the ReferencesResolved condition to True state.
func (ss *SubscriptionStatus) MarkReferencesResolved() {
SubCondSet.Manage(ss).MarkTrue(SubscriptionConditionReferencesResolved)
}
// MarkChannelReady sets the ChannelReady condition to True state.
func (ss *SubscriptionStatus) MarkChannelReady() {
SubCondSet.Manage(ss).MarkTrue(SubscriptionConditionChannelReady)
}
// MarkAddedToChannel sets the AddedToChannel condition to True state.
func (ss *SubscriptionStatus) MarkAddedToChannel() {
SubCondSet.Manage(ss).MarkTrue(SubscriptionConditionAddedToChannel)
}
// MarkReferencesNotResolved sets the ReferencesResolved condition to False state.
func (ss *SubscriptionStatus) MarkReferencesNotResolved(reason, messageFormat string, messageA ...interface{}) {
SubCondSet.Manage(ss).MarkFalse(SubscriptionConditionReferencesResolved, reason, messageFormat, messageA...)
}
// MarkReferencesResolvedUnknown sets the ReferencesResolved condition to Unknown state.
func (ss *SubscriptionStatus) MarkReferencesResolvedUnknown(reason, messageFormat string, messageA ...interface{}) {
SubCondSet.Manage(ss).MarkUnknown(SubscriptionConditionReferencesResolved, reason, messageFormat, messageA...)
}
// MarkChannelFailed sets the ChannelReady condition to False state.
func (ss *SubscriptionStatus) MarkChannelFailed(reason, messageFormat string, messageA ...interface{}) {
SubCondSet.Manage(ss).MarkFalse(SubscriptionConditionChannelReady, reason, messageFormat, messageA...)
}
// MarkChannelUnknown sets the ChannelReady condition to Unknown state.
func (ss *SubscriptionStatus) MarkChannelUnknown(reason, messageFormat string, messageA ...interface{}) {
SubCondSet.Manage(ss).MarkUnknown(SubscriptionConditionChannelReady, reason, messageFormat, messageA...)
}
// MarkNotAddedToChannel sets the AddedToChannel condition to False state.
func (ss *SubscriptionStatus) MarkNotAddedToChannel(reason, messageFormat string, messageA ...interface{}) {
SubCondSet.Manage(ss).MarkFalse(SubscriptionConditionAddedToChannel, reason, messageFormat, messageA...)
}