Skip to content

Commit ce57ad1

Browse files
committed
Add e2e test case for syncSourceState
Signed-off-by: Vu Dinh <[email protected]>
1 parent 5140d19 commit ce57ad1

File tree

1 file changed

+110
-2
lines changed

1 file changed

+110
-2
lines changed

test/e2e/catalog_e2e_test.go

Lines changed: 110 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,114 @@ func TestCatalogLoadingBetweenRestarts(t *testing.T) {
8181
t.Logf("Catalog source sucessfully loaded after rescale")
8282
}
8383

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.ApprovalAutomatic,
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, subscriptionStateAtLatestChecker)
149+
require.NoError(t, err)
150+
require.NotNil(t, subscription)
151+
_, err = fetchCSV(t, crc, subscription.Status.CurrentCSV, testNamespace, buildCSVConditionChecker(v1alpha1.CSVPhaseSucceeded))
152+
require.NoError(t, err)
153+
154+
// Update manifest
155+
mainManifests = []registry.PackageManifest{
156+
{
157+
PackageName: mainPackageName,
158+
Channels: []registry.PackageChannel{
159+
{Name: stableChannel, CurrentCSVName: replacementCSV.GetName()},
160+
},
161+
DefaultChannelName: stableChannel,
162+
},
163+
}
164+
165+
// Update catalog configmap
166+
updateInternalCatalog(t, c, crc, mainCatalogName, globalNS, []apiextensions.CustomResourceDefinition{mainCRD}, []v1alpha1.ClusterServiceVersion{mainCSV, replacementCSV}, mainManifests)
167+
168+
// Get updated catalogsource
169+
fetchedUpdatedCatalog, err := fetchCatalogSource(t, crc, mainCatalogName, globalNS, func(catalog *v1alpha1.CatalogSource) bool {
170+
registry := catalog.Status.RegistryServiceStatus
171+
connState := catalog.Status.GRPCConnectionState
172+
if registry != nil && connState != nil && connState.LastObservedState == "READY" && !connState.LastConnectTime.IsZero() {
173+
fmt.Printf("catalog %s pod with address %s\n", catalog.GetName(), registry.Address())
174+
return registryPodHealthy(registry.Address())
175+
}
176+
fmt.Printf("waiting for catalog pod %v to be available (for sync)\n", catalog.GetName())
177+
return false
178+
})
179+
require.NoError(t, err)
180+
181+
subscription, err = fetchSubscription(t, crc, testNamespace, subscriptionName, subscriptionStateUpgradeAvailableChecker)
182+
require.NoError(t, err)
183+
require.NotNil(t, subscription)
184+
185+
// Ensure the timing
186+
catalogConnState := fetchedUpdatedCatalog.Status.GRPCConnectionState
187+
subUpdatedTime := subscription.Status.LastUpdated
188+
timeLapse := subUpdatedTime.Sub(catalogConnState.LastConnectTime.Time).Seconds()
189+
require.True(t, timeLapse < 60)
190+
}
191+
84192
func TestConfigMapUpdateTriggersRegistryPodRollout(t *testing.T) {
85193
defer cleaner.NotifyTestComplete(t, true)
86194

@@ -153,8 +261,8 @@ func TestConfigMapUpdateTriggersRegistryPodRollout(t *testing.T) {
153261
fetchedUpdatedCatalog, err := fetchCatalogSource(t, crc, mainCatalogName, testNamespace, func(catalog *v1alpha1.CatalogSource) bool {
154262
before := fetchedInitialCatalog.Status.ConfigMapResource
155263
after := catalog.Status.ConfigMapResource
156-
if after != nil && before.LastUpdateTime.Before(&after.LastUpdateTime) &&
157-
after.ResourceVersion != before.ResourceVersion {
264+
if after != nil && before.LastUpdateTime.Before(&after.LastUpdateTime) &&
265+
after.ResourceVersion != before.ResourceVersion {
158266
fmt.Println("catalog updated")
159267
return true
160268
}

0 commit comments

Comments
 (0)