@@ -2,13 +2,14 @@ package controllers_test
2
2
3
3
import (
4
4
"context"
5
+ "encoding/json"
5
6
"fmt"
6
7
7
8
. "github.com/onsi/ginkgo/v2"
8
9
. "github.com/onsi/gomega"
9
- "github.com/operator-framework/deppy/pkg/deppy"
10
- "github.com/operator-framework/deppy/pkg/deppy/input"
11
10
"github.com/operator-framework/deppy/pkg/deppy/solver"
11
+ "github.com/operator-framework/operator-registry/alpha/declcfg"
12
+ "github.com/operator-framework/operator-registry/alpha/property"
12
13
rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1"
13
14
apimeta "k8s.io/apimachinery/pkg/api/meta"
14
15
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -20,21 +21,25 @@ import (
20
21
"sigs.k8s.io/controller-runtime/pkg/client/fake"
21
22
22
23
operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
24
+ "github.com/operator-framework/operator-controller/internal/catalogmetadata"
23
25
"github.com/operator-framework/operator-controller/internal/conditionsets"
24
26
"github.com/operator-framework/operator-controller/internal/controllers"
27
+ testutil "github.com/operator-framework/operator-controller/test/util"
25
28
)
26
29
27
30
var _ = Describe ("Operator Controller Test" , func () {
28
31
var (
29
- ctx context.Context
30
- reconciler * controllers.OperatorReconciler
32
+ ctx context.Context
33
+ fakeCatalogClient testutil.FakeCatalogClient
34
+ reconciler * controllers.OperatorReconciler
31
35
)
32
36
BeforeEach (func () {
33
37
ctx = context .Background ()
38
+ fakeCatalogClient = testutil .NewFakeCatalogClient (testBundleList )
34
39
reconciler = & controllers.OperatorReconciler {
35
40
Client : cl ,
36
41
Scheme : sch ,
37
- Resolver : solver .NewDeppySolver (testEntitySource , controllers .NewVariableSource (cl )),
42
+ Resolver : solver .NewDeppySolver (controllers .NewVariableSource (cl , & fakeCatalogClient )),
38
43
}
39
44
})
40
45
When ("the operator does not exist" , func () {
@@ -575,43 +580,6 @@ var _ = Describe("Operator Controller Test", func() {
575
580
})
576
581
})
577
582
})
578
- When ("the selected bundle's image ref cannot be parsed" , func () {
579
- const pkgName = "badimage"
580
- BeforeEach (func () {
581
- By ("initializing cluster state" )
582
- operator = & operatorsv1alpha1.Operator {
583
- ObjectMeta : metav1.ObjectMeta {Name : opKey .Name },
584
- Spec : operatorsv1alpha1.OperatorSpec {PackageName : pkgName },
585
- }
586
- err := cl .Create (ctx , operator )
587
- Expect (err ).NotTo (HaveOccurred ())
588
- })
589
- It ("sets resolution failure status and returns an error" , func () {
590
- By ("running reconcile" )
591
- res , err := reconciler .Reconcile (ctx , ctrl.Request {NamespacedName : opKey })
592
- Expect (res ).To (Equal (ctrl.Result {}))
593
- Expect (err ).To (MatchError (ContainSubstring (`error determining bundle path for entity` )))
594
-
595
- By ("fetching updated operator after reconcile" )
596
- Expect (cl .Get (ctx , opKey , operator )).NotTo (HaveOccurred ())
597
-
598
- By ("Checking the status fields" )
599
- Expect (operator .Status .ResolvedBundleResource ).To (Equal ("" ))
600
- Expect (operator .Status .InstalledBundleResource ).To (Equal ("" ))
601
-
602
- By ("checking the expected conditions" )
603
- cond := apimeta .FindStatusCondition (operator .Status .Conditions , operatorsv1alpha1 .TypeResolved )
604
- Expect (cond ).NotTo (BeNil ())
605
- Expect (cond .Status ).To (Equal (metav1 .ConditionFalse ))
606
- Expect (cond .Reason ).To (Equal (operatorsv1alpha1 .ReasonResolutionFailed ))
607
- Expect (cond .Message ).To (ContainSubstring (`error determining bundle path for entity` ))
608
- cond = apimeta .FindStatusCondition (operator .Status .Conditions , operatorsv1alpha1 .TypeInstalled )
609
- Expect (cond ).NotTo (BeNil ())
610
- Expect (cond .Status ).To (Equal (metav1 .ConditionUnknown ))
611
- Expect (cond .Reason ).To (Equal (operatorsv1alpha1 .ReasonInstallationStatusUnknown ))
612
- Expect (cond .Message ).To (Equal ("installation has not been attempted as resolution failed" ))
613
- })
614
- })
615
583
When ("the operator specifies a duplicate package" , func () {
616
584
const pkgName = "prometheus"
617
585
var dupOperator * operatorsv1alpha1.Operator
@@ -1080,41 +1048,62 @@ func verifyConditionsInvariants(op *operatorsv1alpha1.Operator) {
1080
1048
}
1081
1049
}
1082
1050
1083
- var testEntitySource = input .NewCacheQuerier (map [deppy.Identifier ]input.Entity {
1084
- "operatorhub/prometheus/0.37.0" : * input .NewEntity ("operatorhub/prometheus/0.37.0" , map [string ]string {
1085
- "olm.bundle.path" : `"quay.io/operatorhubio/prometheus@sha256:3e281e587de3d03011440685fc4fb782672beab044c1ebadc42788ce05a21c35"` ,
1086
- "olm.bundle.channelEntry" : `{"name":"prometheus.0.37.0"}` ,
1087
- "olm.channel" : `{"channelName":"beta","priority":0}` ,
1088
- "olm.package" : `{"packageName":"prometheus","version":"0.37.0"}` ,
1089
- "olm.gvk" : `[]` ,
1090
- }),
1091
- "operatorhub/prometheus/0.47.0" : * input .NewEntity ("operatorhub/prometheus/0.47.0" , map [string ]string {
1092
- "olm.bundle.path" : `"quay.io/operatorhubio/prometheus@sha256:5b04c49d8d3eff6a338b56ec90bdf491d501fe301c9cdfb740e5bff6769a21ed"` ,
1093
- "olm.bundle.channelEntry" : `{"name":"prometheus.0.47.0"}` ,
1094
- "olm.channel" : `{"channelName":"beta","priority":0,"replaces":"prometheusoperator.0.37.0"}` ,
1095
- "olm.package" : `{"packageName":"prometheus","version":"0.47.0"}` ,
1096
- "olm.gvk" : `[]` ,
1097
- }),
1098
- "operatorhub/badimage/0.1.0" : * input .NewEntity ("operatorhub/badimage/0.1.0" , map [string ]string {
1099
- "olm.bundle.path" : `{"name": "quay.io/operatorhubio/badimage:v0.1.0"}` ,
1100
- "olm.bundle.channelEntry" : `{"name":"badimage.0.1.0"}` ,
1101
- "olm.package" : `{"packageName":"badimage","version":"0.1.0"}` ,
1102
- "olm.gvk" : `[]` ,
1103
- }),
1104
- "operatorhub/plain/0.1.0" : * input .NewEntity ("operatorhub/plain/0.1.0" , map [string ]string {
1105
- "olm.bundle.path" : `"quay.io/operatorhub/plain@sha256:plain"` ,
1106
- "olm.bundle.channelEntry" : `{"name":"plain.0.1.0"}` ,
1107
- "olm.channel" : `{"channelName":"beta","priority":0}` ,
1108
- "olm.package" : `{"packageName":"plain","version":"0.1.0"}` ,
1109
- "olm.gvk" : `[]` ,
1110
- "olm.bundle.mediatype" : `"plain+v0"` ,
1111
- }),
1112
- "operatorhub/badmedia/0.1.0" : * input .NewEntity ("operatorhub/badmedia/0.1.0" , map [string ]string {
1113
- "olm.bundle.path" : `"quay.io/operatorhub/badmedia@sha256:badmedia"` ,
1114
- "olm.bundle.channelEntry" : `{"name":"badmedia.0.1.0"}` ,
1115
- "olm.channel" : `{"channelName":"beta","priority":0}` ,
1116
- "olm.package" : `{"packageName":"badmedia","version":"0.1.0"}` ,
1117
- "olm.gvk" : `[]` ,
1118
- "olm.bundle.mediatype" : `"badmedia+v1"` ,
1119
- }),
1120
- })
1051
+ var betaChannel = catalogmetadata.Channel {Channel : declcfg.Channel {
1052
+ Name : "beta" ,
1053
+ Entries : []declcfg.ChannelEntry {
1054
+ {
1055
+ Name : "operatorhub/prometheus/0.37.0" ,
1056
+ },
1057
+ {
1058
+ Name : "operatorhub/prometheus/0.47.0" ,
1059
+ Replaces : "operatorhub/prometheus/0.37.0" ,
1060
+ },
1061
+ {
1062
+ Name : "operatorhub/plain/0.1.0" ,
1063
+ },
1064
+ {
1065
+ Name : "operatorhub/badmedia/0.1.0" ,
1066
+ },
1067
+ },
1068
+ }}
1069
+
1070
+ var testBundleList = []* catalogmetadata.Bundle {
1071
+ {Bundle : declcfg.Bundle {
1072
+ Name : "operatorhub/prometheus/0.37.0" ,
1073
+ Package : "prometheus" ,
1074
+ Image : "quay.io/operatorhubio/prometheus@sha256:3e281e587de3d03011440685fc4fb782672beab044c1ebadc42788ce05a21c35" ,
1075
+ Properties : []property.Property {
1076
+ {Type : property .TypePackage , Value : json .RawMessage (`{"packageName":"prometheus","version":"0.37.0"}` )},
1077
+ {Type : property .TypeGVK , Value : json .RawMessage (`[]` )},
1078
+ },
1079
+ }, InChannels : []* catalogmetadata.Channel {& betaChannel }},
1080
+ {Bundle : declcfg.Bundle {
1081
+ Name : "operatorhub/prometheus/0.47.0" ,
1082
+ Package : "prometheus" ,
1083
+ Image : "quay.io/operatorhubio/prometheus@sha256:5b04c49d8d3eff6a338b56ec90bdf491d501fe301c9cdfb740e5bff6769a21ed" ,
1084
+ Properties : []property.Property {
1085
+ {Type : property .TypePackage , Value : json .RawMessage (`{"packageName":"prometheus","version":"0.47.0"}` )},
1086
+ {Type : property .TypeGVK , Value : json .RawMessage (`[]` )},
1087
+ },
1088
+ }, InChannels : []* catalogmetadata.Channel {& betaChannel }},
1089
+ {Bundle : declcfg.Bundle {
1090
+ Name : "operatorhub/plain/0.1.0" ,
1091
+ Package : "plain" ,
1092
+ Image : "quay.io/operatorhub/plain@sha256:plain" ,
1093
+ Properties : []property.Property {
1094
+ {Type : property .TypePackage , Value : json .RawMessage (`{"packageName":"plain","version":"0.1.0"}` )},
1095
+ {Type : property .TypeGVK , Value : json .RawMessage (`[]` )},
1096
+ {Type : "olm.bundle.mediatype" , Value : json .RawMessage (`"plain+v0"` )},
1097
+ },
1098
+ }, InChannels : []* catalogmetadata.Channel {& betaChannel }},
1099
+ {Bundle : declcfg.Bundle {
1100
+ Name : "operatorhub/badmedia/0.1.0" ,
1101
+ Package : "badmedia" ,
1102
+ Image : "quay.io/operatorhub/badmedia@sha256:badmedia" ,
1103
+ Properties : []property.Property {
1104
+ {Type : property .TypePackage , Value : json .RawMessage (`{"packageName":"badmedia","version":"0.1.0"}` )},
1105
+ {Type : property .TypeGVK , Value : json .RawMessage (`[]` )},
1106
+ {Type : "olm.bundle.mediatype" , Value : json .RawMessage (`"badmedia+v1"` )},
1107
+ },
1108
+ }, InChannels : []* catalogmetadata.Channel {& betaChannel }},
1109
+ }
0 commit comments