Skip to content

Commit d2b8348

Browse files
committed
Add support for Prometheus Custom Resources
This commit introduces support for packaging PrometheusRules and ServiceMonitor CustomResources in a Catalog Bundle. In order to introduce this change, the following changes were made: * OLM can now resolve unknown resources stored in the Catalog Bundle using the dynamic client. This feature is only enabled for PrometheusRule and ServiceMonitor Custom Resources, which are provided by the Prometheus Operator. * The steps of an InstallPlan are now ordered by CSVs, CRDs, and finally the remaining resources.
1 parent ca41ee5 commit d2b8348

File tree

117 files changed

+47740
-36732
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+47740
-36732
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ require (
2929
github.com/stretchr/testify v1.4.0
3030
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 // indirect
3131
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
32+
golang.org/x/sys v0.0.0-20191210023423-ac6580df4449 // indirect
3233
golang.org/x/time v0.0.0-20191024005414-555d28b269f0
3334
gonum.org/v1/gonum v0.0.0-20190710053202-4340aa3071a0 // indirect
3435
google.golang.org/grpc v1.24.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,8 @@ golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb h1:fgwFCsaw9buMuxNd6+DQfAuSF
795795
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
796796
golang.org/x/sys v0.0.0-20191028164358-195ce5e7f934 h1:u/E0NqCIWRDAo9WCFo6Ko49njPFDLSd3z+X1HgWDMpE=
797797
golang.org/x/sys v0.0.0-20191028164358-195ce5e7f934/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
798+
golang.org/x/sys v0.0.0-20191210023423-ac6580df4449 h1:gSbV7h1NRL2G1xTg/owz62CST1oJBmxy4QpMMregXVQ=
799+
golang.org/x/sys v0.0.0-20191210023423-ac6580df4449/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
798800
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
799801
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
800802
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

pkg/api/apis/operators/installplan_types.go

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,12 @@ const (
6363
type StepStatus string
6464

6565
const (
66-
StepStatusUnknown StepStatus = "Unknown"
67-
StepStatusNotPresent StepStatus = "NotPresent"
68-
StepStatusPresent StepStatus = "Present"
69-
StepStatusCreated StepStatus = "Created"
66+
StepStatusUnknown StepStatus = "Unknown"
67+
StepStatusNotPresent StepStatus = "NotPresent"
68+
StepStatusPresent StepStatus = "Present"
69+
StepStatusCreated StepStatus = "Created"
70+
StepStatusWaitingForAPI StepStatus = "WaitingForApi"
71+
StepStatusUnsupportedResource StepStatus = "UnsupportedResource"
7072
)
7173

7274
// ErrInvalidInstallPlan is the error returned by functions that operate on
@@ -168,6 +170,8 @@ type BundleLookupConditionType string
168170
const (
169171
// BundleLookupPending describes BundleLookups that are not complete.
170172
BundleLookupPending BundleLookupConditionType = "BundleLookupPending"
173+
174+
crdKind = "CustomResourceDefinition"
171175
)
172176

173177
type BundleLookupCondition struct {
@@ -248,6 +252,58 @@ func (b *BundleLookup) SetCondition(cond BundleLookupCondition) BundleLookupCond
248252
return cond
249253
}
250254

255+
func OrderSteps(steps []*Step) []*Step {
256+
// CSVs must be applied first
257+
csvList := []*Step{}
258+
259+
// CRDs must be applied second
260+
crdList := []*Step{}
261+
262+
// Other resources may be applied in any order
263+
remainingResources := []*Step{}
264+
for _, step := range steps {
265+
switch step.Resource.Kind {
266+
case crdKind:
267+
crdList = append(crdList, step)
268+
case ClusterServiceVersionKind:
269+
csvList = append(csvList, step)
270+
default:
271+
remainingResources = append(remainingResources, step)
272+
}
273+
}
274+
275+
result := make([]*Step, len(steps))
276+
i := 0
277+
278+
for j := range csvList {
279+
result[i] = csvList[j]
280+
i++
281+
}
282+
283+
for j := range crdList {
284+
result[i] = crdList[j]
285+
i++
286+
}
287+
288+
for j := range remainingResources {
289+
result[i] = remainingResources[j]
290+
i++
291+
}
292+
293+
return result
294+
}
295+
296+
func (s InstallPlanStatus) NeedsRequeue() bool {
297+
for _, step := range s.Plan {
298+
switch step.Status {
299+
case StepStatusWaitingForAPI:
300+
return true
301+
}
302+
}
303+
304+
return false
305+
}
306+
251307
// ManifestsMatch returns true if the CSV manifests in the StepResources of the given list of steps
252308
// matches those in the InstallPlanStatus.
253309
func (s *InstallPlanStatus) CSVManifestsMatch(steps []*Step) bool {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package v1alpha1
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
)
8+
9+
func TestOrderSteps(t *testing.T) {
10+
tests := []struct {
11+
description string
12+
in []*Step
13+
}{
14+
{
15+
description: "EmptyList",
16+
in: []*Step{},
17+
},
18+
{
19+
description: "csvsRDS",
20+
in: []*Step{step(crdKind), step(ClusterServiceVersionKind), step(crdKind), step(crdKind)},
21+
},
22+
{
23+
description: "csvsCRDSAndRandomKinds",
24+
in: []*Step{step(crdKind), step(ClusterServiceVersionKind), step(crdKind), step(crdKind), step("These"), step("are"), step("random"), step("Kinds")},
25+
},
26+
}
27+
28+
for _, tt := range tests {
29+
t.Run(tt.description, func(t *testing.T) {
30+
result := OrderSteps(tt.in)
31+
require.EqualValues(t, len(result), len(tt.in))
32+
require.True(t, isOrdered(result))
33+
})
34+
}
35+
}
36+
37+
func step(kind string) *Step {
38+
resource := StepResource{}
39+
resource.Kind = kind
40+
41+
result := &Step{}
42+
result.Resource = resource
43+
return result
44+
}
45+
46+
func isOrdered(steps []*Step) bool {
47+
var crdSeen, otherResourceSeen bool
48+
for _, step := range steps {
49+
switch step.Resource.Kind {
50+
case ClusterServiceVersionKind:
51+
if crdSeen || otherResourceSeen {
52+
return false
53+
}
54+
case crdKind:
55+
crdSeen = true
56+
if otherResourceSeen {
57+
return false
58+
}
59+
default:
60+
otherResourceSeen = true
61+
}
62+
}
63+
return true
64+
}

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

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,12 @@ const (
6565
type StepStatus string
6666

6767
const (
68-
StepStatusUnknown StepStatus = "Unknown"
69-
StepStatusNotPresent StepStatus = "NotPresent"
70-
StepStatusPresent StepStatus = "Present"
71-
StepStatusCreated StepStatus = "Created"
68+
StepStatusUnknown StepStatus = "Unknown"
69+
StepStatusNotPresent StepStatus = "NotPresent"
70+
StepStatusPresent StepStatus = "Present"
71+
StepStatusCreated StepStatus = "Created"
72+
StepStatusWaitingForAPI StepStatus = "WaitingForApi"
73+
StepStatusUnsupportedResource StepStatus = "UnsupportedResource"
7274
)
7375

7476
// ErrInvalidInstallPlan is the error returned by functions that operate on
@@ -137,6 +139,57 @@ func (s *InstallPlanStatus) SetCondition(cond InstallPlanCondition) InstallPlanC
137139
return cond
138140
}
139141

142+
func OrderSteps(steps []*Step) []*Step {
143+
// CSVs must be applied first
144+
csvList := []*Step{}
145+
146+
// CRDs must be applied second
147+
crdList := []*Step{}
148+
149+
// Other resources may be applied in any order
150+
remainingResources := []*Step{}
151+
for _, step := range steps {
152+
switch step.Resource.Kind {
153+
case crdKind:
154+
crdList = append(crdList, step)
155+
case ClusterServiceVersionKind:
156+
csvList = append(csvList, step)
157+
default:
158+
remainingResources = append(remainingResources, step)
159+
}
160+
}
161+
162+
result := make([]*Step, len(steps))
163+
i := 0
164+
165+
for j := range csvList {
166+
result[i] = csvList[j]
167+
i++
168+
}
169+
170+
for j := range crdList {
171+
result[i] = crdList[j]
172+
i++
173+
}
174+
175+
for j := range remainingResources {
176+
result[i] = remainingResources[j]
177+
i++
178+
}
179+
180+
return result
181+
}
182+
183+
func (s InstallPlanStatus) NeedsRequeue() bool {
184+
for _, step := range s.Plan {
185+
switch step.Status {
186+
case StepStatusWaitingForAPI:
187+
return true
188+
}
189+
}
190+
191+
return false
192+
}
140193
func ConditionFailed(cond InstallPlanConditionType, reason InstallPlanConditionReason, message string, now *metav1.Time) InstallPlanCondition {
141194
return InstallPlanCondition{
142195
Type: cond,
@@ -170,6 +223,8 @@ type BundleLookupConditionType string
170223
const (
171224
// BundleLookupPending describes BundleLookups that are not complete.
172225
BundleLookupPending BundleLookupConditionType = "BundleLookupPending"
226+
227+
crdKind = "CustomResourceDefinition"
173228
)
174229

175230
type BundleLookupCondition struct {

0 commit comments

Comments
 (0)