Skip to content

Commit 73c00f8

Browse files
Merge pull request #923 from njhale/sub-ips
Add Subscription InstallPlan Status
2 parents 6bf64d0 + e9ca2b1 commit 73c00f8

File tree

27 files changed

+4668
-404
lines changed

27 files changed

+4668
-404
lines changed

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ require (
2727
github.com/google/btree v1.0.0 // indirect
2828
github.com/google/go-cmp v0.2.0 // indirect
2929
github.com/google/gofuzz v1.0.0 // indirect
30+
github.com/googleapis/gnostic v0.3.0 // indirect
3031
github.com/grpc-ecosystem/grpc-gateway v1.8.5 // indirect
3132
github.com/json-iterator/go v1.1.6 // indirect
3233
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
3334
github.com/maxbrunsfeld/counterfeiter/v6 v6.0.2
35+
github.com/mitchellh/hashstructure v1.0.0
3436
github.com/onsi/ginkgo v1.8.0 // indirect
3537
github.com/openshift/api v3.9.1-0.20190424152011-77b8897ec79a+incompatible
3638
github.com/openshift/client-go v0.0.0-20190401163519-84c2b942258a
@@ -58,7 +60,7 @@ require (
5860
k8s.io/klog v0.2.0 // indirect
5961
k8s.io/kube-aggregator v0.0.0-20190404125450-f5e124c822d6
6062
k8s.io/kube-openapi v0.0.0-20190401085232-94e1e7b7574c
61-
k8s.io/kubernetes v1.14.2
63+
k8s.io/kubernetes v1.14.3
6264
k8s.io/utils v0.0.0-20190308190857-21c4ce38f2a7 // indirect
6365
sigs.k8s.io/yaml v1.1.0 // indirect
6466
)

go.sum

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,15 @@ github.com/google/uuid v1.0.0 h1:b4Gk+7WdP/d3HZH8EJsZpvV7EtDOgaZLtnaNGIu1adA=
127127
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
128128
github.com/googleapis/gnostic v0.2.0 h1:l6N3VoaVzTncYYW+9yOz2LJJammFZGBO13sqgEhpy9g=
129129
github.com/googleapis/gnostic v0.2.0/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
130+
github.com/googleapis/gnostic v0.3.0 h1:CcQijm0XKekKjP/YCz28LXVSpgguuB+nCxaSjCe09y0=
131+
github.com/googleapis/gnostic v0.3.0/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
130132
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
131133
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
132134
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
133135
github.com/gregjones/httpcache v0.0.0-20181110185634-c63ab54fda8f/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
134136
github.com/gregjones/httpcache v0.0.0-20190203031600-7a902570cb17 h1:prg2TTpTOcJF1jRWL2zSU1FQNgB0STAFNux8GK82y8k=
135137
github.com/gregjones/httpcache v0.0.0-20190203031600-7a902570cb17/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
136-
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0 h1:BWIsLfhgKhV5g/oF34aRjniBHLTZe5DNekSjbAjIS6c=
138+
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0 h1:Iju5GlWwrvL6UBg4zJJt3btmonfrMlCDdsejg4CZE7c=
137139
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
138140
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho=
139141
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
@@ -182,6 +184,8 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5
182184
github.com/maxbrunsfeld/counterfeiter v0.0.0-20181017030959-1aadac120687/go.mod h1:aoVsckWnsNzazwF2kmD+bzgdr4GBlbK91zsdivQJ2eU=
183185
github.com/maxbrunsfeld/counterfeiter/v6 v6.0.2 h1:pbpJx2aGTIexkk+R+XLnCA9r2TBLg8KKyDo4GvaJan0=
184186
github.com/maxbrunsfeld/counterfeiter/v6 v6.0.2/go.mod h1:jDaYg8/bmdfygnyq5gnvMRDocYTEcXLPU0bXPtTco58=
187+
github.com/mitchellh/hashstructure v1.0.0 h1:ZkRJX1CyOoTkar7p/mLS5TZU4nJ1Rn/F8u9dGS02Q3Y=
188+
github.com/mitchellh/hashstructure v1.0.0/go.mod h1:QjSHrPWS+BGUVBYkbTZWEnOh3G1DutKwClXU/ABz6AQ=
185189
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
186190
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
187191
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
@@ -388,8 +392,8 @@ k8s.io/kube-openapi v0.0.0-20180711000925-0cf8f7e6ed1d h1:mn2F9UzCk6KGa7M/d2ibLy
388392
k8s.io/kube-openapi v0.0.0-20180711000925-0cf8f7e6ed1d/go.mod h1:BXM9ceUBTj2QnfH2MK1odQs778ajze1RxcmP6S8RVVc=
389393
k8s.io/kubernetes v1.11.7-beta.0.0.20181219023948-b875d52ea96d/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk=
390394
k8s.io/kubernetes v1.11.8-beta.0.0.20190124204751-3a10094374f2/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk=
391-
k8s.io/kubernetes v1.14.2 h1:Gdq2hPpttbaJBoClIanCE6WSu4IZReA54yhkZtvPUOo=
392-
k8s.io/kubernetes v1.14.2/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk=
395+
k8s.io/kubernetes v1.14.3 h1:/FQkOJpjc1jGA37s7Rt3U10VwIKW685ejrgOp4UDRFE=
396+
k8s.io/kubernetes v1.14.3/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk=
393397
k8s.io/utils v0.0.0-20190308190857-21c4ce38f2a7 h1:8r+l4bNWjRlsFYlQJnKJ2p7s1YQPj4XyXiJVqDHRx7c=
394398
k8s.io/utils v0.0.0-20190308190857-21c4ce38f2a7/go.mod h1:8k8uAuAQ0rXslZKaEWd0c3oVhZz7sSzSiPnVZayjIX0=
395399
sigs.k8s.io/controller-runtime v0.1.10/go.mod h1:HFAYoOh6XMV+jKF1UjFwrknPbowfyHEHHRdJMf2jMX8=

pkg/api/apis/operators/installplan_types.go

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,23 @@ type InstallPlanCondition struct {
9898
// allow overwriting `now` function for deterministic tests
9999
var now = metav1.Now
100100

101-
// SetCondition adds or updates a condition, using `Type` as merge key
102-
func (s *InstallPlanStatus) SetCondition(cond InstallPlanCondition) InstallPlanCondition {
103-
updated := now()
104-
cond.LastUpdateTime = updated
105-
cond.LastTransitionTime = updated
101+
// GetCondition returns the InstallPlanCondition of the given type if it exists in the InstallPlanStatus' Conditions.
102+
// Returns a condition of the given type with a ConditionStatus of "Unknown" if not found.
103+
func (s InstallPlanStatus) GetCondition(conditionType InstallPlanConditionType) InstallPlanCondition {
104+
for _, cond := range s.Conditions {
105+
if cond.Type == conditionType {
106+
return cond
107+
}
108+
}
109+
110+
return InstallPlanCondition{
111+
Type: conditionType,
112+
Status: corev1.ConditionUnknown,
113+
}
114+
}
106115

116+
// SetCondition adds or updates a condition, using `Type` as merge key.
117+
func (s *InstallPlanStatus) SetCondition(cond InstallPlanCondition) InstallPlanCondition {
107118
for i, existing := range s.Conditions {
108119
if existing.Type != cond.Type {
109120
continue
@@ -118,19 +129,23 @@ func (s *InstallPlanStatus) SetCondition(cond InstallPlanCondition) InstallPlanC
118129
return cond
119130
}
120131

121-
func ConditionFailed(cond InstallPlanConditionType, reason InstallPlanConditionReason, err error) InstallPlanCondition {
132+
func ConditionFailed(cond InstallPlanConditionType, reason InstallPlanConditionReason, message string, now *metav1.Time) InstallPlanCondition {
122133
return InstallPlanCondition{
123-
Type: cond,
124-
Status: corev1.ConditionFalse,
125-
Reason: reason,
126-
Message: err.Error(),
134+
Type: cond,
135+
Status: corev1.ConditionFalse,
136+
Reason: reason,
137+
Message: message,
138+
LastUpdateTime: *now,
139+
LastTransitionTime: *now,
127140
}
128141
}
129142

130-
func ConditionMet(cond InstallPlanConditionType) InstallPlanCondition {
143+
func ConditionMet(cond InstallPlanConditionType, now *metav1.Time) InstallPlanCondition {
131144
return InstallPlanCondition{
132-
Type: cond,
133-
Status: corev1.ConditionTrue,
145+
Type: cond,
146+
Status: corev1.ConditionTrue,
147+
LastUpdateTime: *now,
148+
LastTransitionTime: *now,
134149
}
135150
}
136151

pkg/api/apis/operators/subscription_types.go

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,47 @@ type SubscriptionConditionType string
4242
const (
4343
// SubscriptionCatalogSourcesUnhealthy indicates that some or all of the CatalogSources to be used in resolution are unhealthy.
4444
SubscriptionCatalogSourcesUnhealthy SubscriptionConditionType = "CatalogSourcesUnhealthy"
45+
46+
// SubscriptionInstallPlanMissing indicates that a Subscription's InstallPlan is missing.
47+
SubscriptionInstallPlanMissing SubscriptionConditionType = "InstallPlanMissing"
48+
49+
// SubscriptionInstallPlanPending indicates that a Subscription's InstallPlan is pending installation.
50+
SubscriptionInstallPlanPending SubscriptionConditionType = "InstallPlanPending"
51+
52+
// SubscriptionInstallPlanFailed indicates that the installation of a Subscription's InstallPlan has failed.
53+
SubscriptionInstallPlanFailed SubscriptionConditionType = "InstallPlanFailed"
4554
)
4655

4756
const (
4857
// NoCatalogSourcesFound is a reason string for Subscriptions with unhealthy CatalogSources due to none being available.
4958
NoCatalogSourcesFound = "NoCatalogSourcesFound"
5059

51-
// AllCatalogSourcesHealthy is a reason string for Subscriptions whose CatalogSources are all healthy.
60+
// AllCatalogSourcesHealthy is a reason string for Subscriptions that transitioned due to all CatalogSources being healthy.
5261
AllCatalogSourcesHealthy = "AllCatalogSourcesHealthy"
5362

5463
// CatalogSourcesAdded is a reason string for Subscriptions that transitioned due to CatalogSources being added.
5564
CatalogSourcesAdded = "CatalogSourcesAdded"
5665

57-
// CatalogSourcesUpdated is a reason string for Subscriptions that transitioned due to CatalogSource being updated..
66+
// CatalogSourcesUpdated is a reason string for Subscriptions that transitioned due to CatalogSource being updated.
5867
CatalogSourcesUpdated = "CatalogSourcesUpdated"
5968

6069
// CatalogSourcesDeleted is a reason string for Subscriptions that transitioned due to CatalogSources being removed.
6170
CatalogSourcesDeleted = "CatalogSourcesDeleted"
6271

6372
// UnhealthyCatalogSourceFound is a reason string for Subscriptions that transitioned because an unhealthy CatalogSource was found.
6473
UnhealthyCatalogSourceFound = "UnhealthyCatalogSourceFound"
74+
75+
// ReferencedInstallPlanNotFound is a reason string for Subscriptions that transitioned due to a referenced InstallPlan not being found.
76+
ReferencedInstallPlanNotFound = "ReferencedInstallPlanNotFound"
77+
78+
// InstallPlanNotYetReconciled is a reason string for Subscriptions that transitioned due to a referenced InstallPlan not being reconciled yet.
79+
InstallPlanNotYetReconciled = "InstallPlanNotYetReconciled"
80+
81+
// InstallPlanFailed is a reason string for Subscriptions that transitioned due to a referenced InstallPlan failing without setting an explicit failure condition.
82+
InstallPlanFailed = "InstallPlanFailed"
6583
)
6684

85+
// SubscriptionCondition represents the latest available observations of a Subscription's state.
6786
type SubscriptionCondition struct {
6887
// Type is the type of Subscription condition.
6988
Type SubscriptionConditionType
@@ -127,16 +146,16 @@ type SubscriptionStatus struct {
127146

128147
// Conditions is a list of the latest available observations about a Subscription's current state.
129148
// +optional
130-
Conditions []SubscriptionCondition
149+
Conditions []SubscriptionCondition `hash:"set"`
131150

132151
// LastUpdated represents the last time that the Subscription status was updated.
133152
LastUpdated metav1.Time
134153
}
135154

136155
// GetCondition returns the SubscriptionCondition of the given type if it exists in the SubscriptionStatus' Conditions.
137156
// Returns a condition of the given type with a ConditionStatus of "Unknown" if not found.
138-
func (status SubscriptionStatus) GetCondition(conditionType SubscriptionConditionType) SubscriptionCondition {
139-
for _, cond := range status.Conditions {
157+
func (s SubscriptionStatus) GetCondition(conditionType SubscriptionConditionType) SubscriptionCondition {
158+
for _, cond := range s.Conditions {
140159
if cond.Type == conditionType {
141160
return cond
142161
}
@@ -149,15 +168,34 @@ func (status SubscriptionStatus) GetCondition(conditionType SubscriptionConditio
149168
}
150169

151170
// SetCondition sets the given SubscriptionCondition in the SubscriptionStatus' Conditions.
152-
func (status *SubscriptionStatus) SetCondition(condition SubscriptionCondition) {
153-
for i, cond := range status.Conditions {
171+
func (s *SubscriptionStatus) SetCondition(condition SubscriptionCondition) {
172+
for i, cond := range s.Conditions {
154173
if cond.Type == condition.Type {
155-
status.Conditions[i] = condition
174+
s.Conditions[i] = condition
156175
return
157176
}
158177
}
159178

160-
status.Conditions = append(status.Conditions, condition)
179+
s.Conditions = append(s.Conditions, condition)
180+
}
181+
182+
// RemoveConditions removes any conditions of the given types from the SubscriptionStatus' Conditions.
183+
func (s *SubscriptionStatus) RemoveConditions(remove ...SubscriptionConditionType) {
184+
exclusions := map[SubscriptionConditionType]struct{}{}
185+
for _, r := range remove {
186+
exclusions[r] = struct{}{}
187+
}
188+
189+
var filtered []SubscriptionCondition
190+
for _, cond := range s.Conditions {
191+
if _, ok := exclusions[cond.Type]; ok {
192+
// Skip excluded condition types
193+
continue
194+
}
195+
filtered = append(filtered, cond)
196+
}
197+
198+
s.Conditions = filtered
161199
}
162200

163201
type InstallPlanReference struct {

pkg/api/apis/operators/v1alpha1/installplan_types.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,23 @@ type InstallPlanCondition struct {
100100
// allow overwriting `now` function for deterministic tests
101101
var now = metav1.Now
102102

103-
// SetCondition adds or updates a condition, using `Type` as merge key
104-
func (s *InstallPlanStatus) SetCondition(cond InstallPlanCondition) InstallPlanCondition {
105-
updated := now()
106-
cond.LastUpdateTime = updated
107-
cond.LastTransitionTime = updated
103+
// GetCondition returns the InstallPlanCondition of the given type if it exists in the InstallPlanStatus' Conditions.
104+
// Returns a condition of the given type with a ConditionStatus of "Unknown" if not found.
105+
func (s InstallPlanStatus) GetCondition(conditionType InstallPlanConditionType) InstallPlanCondition {
106+
for _, cond := range s.Conditions {
107+
if cond.Type == conditionType {
108+
return cond
109+
}
110+
}
108111

112+
return InstallPlanCondition{
113+
Type: conditionType,
114+
Status: corev1.ConditionUnknown,
115+
}
116+
}
117+
118+
// SetCondition adds or updates a condition, using `Type` as merge key.
119+
func (s *InstallPlanStatus) SetCondition(cond InstallPlanCondition) InstallPlanCondition {
109120
for i, existing := range s.Conditions {
110121
if existing.Type != cond.Type {
111122
continue
@@ -120,19 +131,24 @@ func (s *InstallPlanStatus) SetCondition(cond InstallPlanCondition) InstallPlanC
120131
return cond
121132
}
122133

123-
func ConditionFailed(cond InstallPlanConditionType, reason InstallPlanConditionReason, err error) InstallPlanCondition {
134+
135+
func ConditionFailed(cond InstallPlanConditionType, reason InstallPlanConditionReason, message string, now *metav1.Time) InstallPlanCondition {
124136
return InstallPlanCondition{
125137
Type: cond,
126138
Status: corev1.ConditionFalse,
127139
Reason: reason,
128-
Message: err.Error(),
140+
Message: message,
141+
LastUpdateTime: *now,
142+
LastTransitionTime: *now,
129143
}
130144
}
131145

132-
func ConditionMet(cond InstallPlanConditionType) InstallPlanCondition {
146+
func ConditionMet(cond InstallPlanConditionType, now *metav1.Time) InstallPlanCondition {
133147
return InstallPlanCondition{
134148
Type: cond,
135149
Status: corev1.ConditionTrue,
150+
LastUpdateTime: *now,
151+
LastTransitionTime: *now,
136152
}
137153
}
138154

0 commit comments

Comments
 (0)