@@ -81,6 +81,115 @@ func TestCatalogLoadingBetweenRestarts(t *testing.T) {
81
81
t .Logf ("Catalog source sucessfully loaded after rescale" )
82
82
}
83
83
84
+ func TestGlobalCatalogUpdateTriggersSubscriptionSync (t * testing.T ) {
85
+ defer cleaner .NotifyTestComplete (t , true )
86
+
87
+ globalNS := operatorNamespace
88
+ c := newKubeClient (t )
89
+ crc := newCRClient (t )
90
+
91
+ // Determine which namespace is global. Should be `openshift-marketplace` for OCP 4.2+.
92
+ // Locally it is `olm`
93
+ namespaces , _ := c .KubernetesInterface ().CoreV1 ().Namespaces ().List (metav1.ListOptions {})
94
+ for _ , ns := range namespaces .Items {
95
+ if ns .GetName () == "openshift-marketplace" {
96
+ globalNS = "openshift-marketplace"
97
+ }
98
+ }
99
+
100
+ mainPackageName := genName ("nginx-" )
101
+
102
+ mainPackageStable := fmt .Sprintf ("%s-stable" , mainPackageName )
103
+ mainPackageReplacement := fmt .Sprintf ("%s-replacement" , mainPackageStable )
104
+
105
+ stableChannel := "stable"
106
+
107
+ mainNamedStrategy := newNginxInstallStrategy (genName ("dep-" ), nil , nil )
108
+
109
+ crdPlural := genName ("ins-" )
110
+
111
+ mainCRD := newCRD (crdPlural )
112
+ mainCSV := newCSV (mainPackageStable , testNamespace , "" , semver .MustParse ("0.1.0" ), []apiextensions.CustomResourceDefinition {mainCRD }, nil , mainNamedStrategy )
113
+ replacementCSV := newCSV (mainPackageReplacement , testNamespace , mainPackageStable , semver .MustParse ("0.2.0" ), []apiextensions.CustomResourceDefinition {mainCRD }, nil , mainNamedStrategy )
114
+
115
+ mainCatalogName := genName ("mock-ocs-main-" )
116
+
117
+ // Create separate manifests for each CatalogSource
118
+ mainManifests := []registry.PackageManifest {
119
+ {
120
+ PackageName : mainPackageName ,
121
+ Channels : []registry.PackageChannel {
122
+ {Name : stableChannel , CurrentCSVName : mainPackageStable },
123
+ },
124
+ DefaultChannelName : stableChannel ,
125
+ },
126
+ }
127
+
128
+ // Create the initial catalogsource
129
+ createInternalCatalogSource (t , c , crc , mainCatalogName , globalNS , mainManifests , []apiextensions.CustomResourceDefinition {mainCRD }, []v1alpha1.ClusterServiceVersion {mainCSV })
130
+
131
+ // Attempt to get the catalog source before creating install plan
132
+ _ , err := fetchCatalogSource (t , crc , mainCatalogName , globalNS , catalogSourceRegistryPodSynced )
133
+ require .NoError (t , err )
134
+
135
+ subscriptionSpec := & v1alpha1.SubscriptionSpec {
136
+ CatalogSource : mainCatalogName ,
137
+ CatalogSourceNamespace : globalNS ,
138
+ Package : mainPackageName ,
139
+ Channel : stableChannel ,
140
+ StartingCSV : mainCSV .GetName (),
141
+ InstallPlanApproval : v1alpha1 .ApprovalManual ,
142
+ }
143
+
144
+ // Create Subscription
145
+ subscriptionName := genName ("sub-" )
146
+ createSubscriptionForCatalogWithSpec (t , crc , testNamespace , subscriptionName , subscriptionSpec )
147
+
148
+ subscription , err := fetchSubscription (t , crc , testNamespace , subscriptionName , subscriptionHasInstallPlanChecker )
149
+ require .NoError (t , err )
150
+ require .NotNil (t , subscription )
151
+
152
+ installPlanName := subscription .Status .Install .Name
153
+ requiresApprovalChecker := buildInstallPlanPhaseCheckFunc (v1alpha1 .InstallPlanPhaseRequiresApproval )
154
+ fetchedInstallPlan , err := fetchInstallPlan (t , crc , installPlanName , requiresApprovalChecker )
155
+ require .NoError (t , err )
156
+
157
+ fetchedInstallPlan .Spec .Approved = true
158
+ _ , err = crc .OperatorsV1alpha1 ().InstallPlans (testNamespace ).Update (fetchedInstallPlan )
159
+ require .NoError (t , err )
160
+
161
+ _ , err = awaitCSV (t , crc , testNamespace , mainCSV .GetName (), csvSucceededChecker )
162
+ require .NoError (t , err )
163
+
164
+ // Update manifest
165
+ mainManifests = []registry.PackageManifest {
166
+ {
167
+ PackageName : mainPackageName ,
168
+ Channels : []registry.PackageChannel {
169
+ {Name : stableChannel , CurrentCSVName : replacementCSV .GetName ()},
170
+ },
171
+ DefaultChannelName : stableChannel ,
172
+ },
173
+ }
174
+
175
+ // Update catalog configmap
176
+ updateInternalCatalog (t , c , crc , mainCatalogName , globalNS , []apiextensions.CustomResourceDefinition {mainCRD }, []v1alpha1.ClusterServiceVersion {mainCSV , replacementCSV }, mainManifests )
177
+
178
+ // Get updated catalogsource
179
+ fetchedUpdatedCatalog , err := fetchCatalogSource (t , crc , mainCatalogName , globalNS , catalogSourceRegistryPodSynced )
180
+ require .NoError (t , err )
181
+
182
+ subscription , err = fetchSubscription (t , crc , testNamespace , subscriptionName , subscriptionStateUpgradePendingChecker )
183
+ require .NoError (t , err )
184
+ require .NotNil (t , subscription )
185
+
186
+ // Ensure the timing
187
+ catalogConnState := fetchedUpdatedCatalog .Status .GRPCConnectionState
188
+ subUpdatedTime := subscription .Status .LastUpdated
189
+ timeLapse := subUpdatedTime .Sub (catalogConnState .LastConnectTime .Time ).Seconds ()
190
+ require .True (t , timeLapse < 60 )
191
+ }
192
+
84
193
func TestConfigMapUpdateTriggersRegistryPodRollout (t * testing.T ) {
85
194
defer cleaner .NotifyTestComplete (t , true )
86
195
@@ -153,8 +262,8 @@ func TestConfigMapUpdateTriggersRegistryPodRollout(t *testing.T) {
153
262
fetchedUpdatedCatalog , err := fetchCatalogSource (t , crc , mainCatalogName , testNamespace , func (catalog * v1alpha1.CatalogSource ) bool {
154
263
before := fetchedInitialCatalog .Status .ConfigMapResource
155
264
after := catalog .Status .ConfigMapResource
156
- if after != nil && before .LastUpdateTime .Before (& after .LastUpdateTime ) &&
157
- after .ResourceVersion != before .ResourceVersion {
265
+ if after != nil && before .LastUpdateTime .Before (& after .LastUpdateTime ) &&
266
+ after .ResourceVersion != before .ResourceVersion {
158
267
fmt .Println ("catalog updated" )
159
268
return true
160
269
}
0 commit comments