Skip to content

Commit 91fffbf

Browse files
committed
(e2e) fix e2e test flakes
1 parent 7ea5b69 commit 91fffbf

File tree

2 files changed

+34
-32
lines changed

2 files changed

+34
-32
lines changed

test/e2e/subscription_e2e_test.go

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ func createSubscription(t *testing.T, crc versioned.Interface, namespace, name,
407407
return buildSubscriptionCleanupFunc(t, crc, subscription)
408408
}
409409

410-
func createSubscriptionWithPodConfig(t *testing.T, crc versioned.Interface, namespace, name, packageName, channel string, approval v1alpha1.Approval, config v1alpha1.SubscriptionConfig) cleanupFunc {
410+
func createSubscriptionForCatalog(t *testing.T, crc versioned.Interface, namespace, name, catalog, packageName, channel, startingCSV string, approval v1alpha1.Approval) cleanupFunc {
411411
subscription := &v1alpha1.Subscription{
412412
TypeMeta: metav1.TypeMeta{
413413
Kind: v1alpha1.SubscriptionKind,
@@ -418,12 +418,12 @@ func createSubscriptionWithPodConfig(t *testing.T, crc versioned.Interface, name
418418
Name: name,
419419
},
420420
Spec: &v1alpha1.SubscriptionSpec{
421-
CatalogSource: catalogSourceName,
421+
CatalogSource: catalog,
422422
CatalogSourceNamespace: namespace,
423423
Package: packageName,
424424
Channel: channel,
425+
StartingCSV: startingCSV,
425426
InstallPlanApproval: approval,
426-
Config: config,
427427
},
428428
}
429429

@@ -432,7 +432,7 @@ func createSubscriptionWithPodConfig(t *testing.T, crc versioned.Interface, name
432432
return buildSubscriptionCleanupFunc(t, crc, subscription)
433433
}
434434

435-
func createSubscriptionForCatalog(t *testing.T, crc versioned.Interface, namespace, name, catalog, packageName, channel, startingCSV string, approval v1alpha1.Approval) cleanupFunc {
435+
func createSubscriptionForCatalogWithSpec(t *testing.T, crc versioned.Interface, namespace, name string, spec *v1alpha1.SubscriptionSpec) cleanupFunc {
436436
subscription := &v1alpha1.Subscription{
437437
TypeMeta: metav1.TypeMeta{
438438
Kind: v1alpha1.SubscriptionKind,
@@ -442,14 +442,7 @@ func createSubscriptionForCatalog(t *testing.T, crc versioned.Interface, namespa
442442
Namespace: namespace,
443443
Name: name,
444444
},
445-
Spec: &v1alpha1.SubscriptionSpec{
446-
CatalogSource: catalog,
447-
CatalogSourceNamespace: namespace,
448-
Package: packageName,
449-
Channel: channel,
450-
StartingCSV: startingCSV,
451-
InstallPlanApproval: approval,
452-
},
445+
Spec: spec,
453446
}
454447

455448
subscription, err := crc.OperatorsV1alpha1().Subscriptions(namespace).Create(subscription)
@@ -1165,15 +1158,10 @@ func TestCreateNewSubscriptionWithPodConfig(t *testing.T) {
11651158
return proxyEnv
11661159
}
11671160

1168-
c := newKubeClient(t)
1169-
crc := newCRClient(t)
1161+
kubeClient := newKubeClient(t)
1162+
crClient := newCRClient(t)
11701163
config := newConfigClient(t)
11711164

1172-
defer func() {
1173-
require.NoError(t, crc.OperatorsV1alpha1().Subscriptions(testNamespace).DeleteCollection(&metav1.DeleteOptions{}, metav1.ListOptions{}))
1174-
}()
1175-
require.NoError(t, initCatalog(t, c, crc))
1176-
11771165
podEnv := []corev1.EnvVar{
11781166
corev1.EnvVar{
11791167
Name: "MY_ENV_VARIABLE1",
@@ -1188,22 +1176,31 @@ func TestCreateNewSubscriptionWithPodConfig(t *testing.T) {
11881176
Env: podEnv,
11891177
}
11901178

1191-
subscriptionName := "mysub-podconfig"
1192-
cleanup := createSubscriptionWithPodConfig(t, crc, testNamespace, subscriptionName, testPackageName, betaChannel, v1alpha1.ApprovalAutomatic, podConfig)
1193-
defer cleanup()
1179+
permissions := deploymentPermissions(t)
1180+
catsrc, subSpec, catsrcCleanup := newCatalogSource(t, kubeClient, crClient, "podconfig", testNamespace, permissions)
1181+
defer catsrcCleanup()
1182+
1183+
// Ensure that the catalog source is resolved before we create a subscription.
1184+
_, err := fetchCatalogSource(t, crClient, catsrc.GetName(), testNamespace, catalogSourceRegistryPodSynced)
1185+
require.NoError(t, err)
1186+
1187+
subscriptionName := genName("podconfig-sub-")
1188+
subSpec.Config = podConfig
1189+
cleanupSubscription := createSubscriptionForCatalogWithSpec(t, crClient, testNamespace, subscriptionName, subSpec)
1190+
defer cleanupSubscription()
11941191

1195-
subscription, err := fetchSubscription(t, crc, testNamespace, subscriptionName, subscriptionStateAtLatestChecker)
1192+
subscription, err := fetchSubscription(t, crClient, testNamespace, subscriptionName, subscriptionStateAtLatestChecker)
11961193
require.NoError(t, err)
11971194
require.NotNil(t, subscription)
11981195

1199-
csv, err := fetchCSV(t, crc, subscription.Status.CurrentCSV, testNamespace, buildCSVConditionChecker(v1alpha1.CSVPhaseSucceeded))
1196+
csv, err := fetchCSV(t, crClient, subscription.Status.CurrentCSV, testNamespace, buildCSVConditionChecker(v1alpha1.CSVPhaseSucceeded))
12001197
require.NoError(t, err)
12011198

12021199
proxyEnv := proxyEnvVarFunc(t, config)
12031200
expected := podEnv
12041201
expected = append(expected, proxyEnv...)
12051202

1206-
checkDeploymentWithPodConfiguration(t, c, csv, podConfig.Env)
1203+
checkDeploymentWithPodConfiguration(t, kubeClient, csv, podConfig.Env)
12071204
}
12081205

12091206
func checkDeploymentWithPodConfiguration(t *testing.T, client operatorclient.ClientInterface, csv *v1alpha1.ClusterServiceVersion, envVar []corev1.EnvVar) {

test/e2e/user_defined_sa_test.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ func TestUserDefinedServiceAccountWithNoPermission(t *testing.T) {
4040
_, cleanupOG := newOperatorGroupWithServiceAccount(t, crclient, namespace, ogName, saName)
4141
defer cleanupOG()
4242

43-
catsrc, subSpec, catsrcCleanup := newCatalogSource(t, kubeclient, crclient, namespace)
43+
permissions := deploymentPermissions(t)
44+
catsrc, subSpec, catsrcCleanup := newCatalogSource(t, kubeclient, crclient, "scoped", namespace, permissions)
4445
defer catsrcCleanup()
4546

4647
// Ensure that the catalog source is resolved before we create a subscription.
@@ -96,7 +97,8 @@ func TestUserDefinedServiceAccountWithPermission(t *testing.T) {
9697
_, cleanupOG := newOperatorGroupWithServiceAccount(t, crclient, namespace, ogName, saName)
9798
defer cleanupOG()
9899

99-
catsrc, subSpec, catsrcCleanup := newCatalogSource(t, kubeclient, crclient, namespace)
100+
permissions := deploymentPermissions(t)
101+
catsrc, subSpec, catsrcCleanup := newCatalogSource(t, kubeclient, crclient, "scoped", namespace, permissions)
100102
defer catsrcCleanup()
101103

102104
// Ensure that the catalog source is resolved before we create a subscription.
@@ -194,7 +196,7 @@ func newOperatorGroupWithServiceAccount(t *testing.T, client versioned.Interface
194196
return
195197
}
196198

197-
func newCatalogSource(t *testing.T, kubeclient operatorclient.ClientInterface, crclient versioned.Interface, namespace string) (catsrc *v1alpha1.CatalogSource, subscriptionSpec *v1alpha1.SubscriptionSpec, cleanup cleanupFunc) {
199+
func newCatalogSource(t *testing.T, kubeclient operatorclient.ClientInterface, crclient versioned.Interface, prefix, namespace string, permissions []install.StrategyDeploymentPermissions) (catsrc *v1alpha1.CatalogSource, subscriptionSpec *v1alpha1.SubscriptionSpec, cleanup cleanupFunc) {
198200
crdPlural := genName("ins")
199201
crdName := crdPlural + ".cluster.com"
200202

@@ -215,12 +217,15 @@ func newCatalogSource(t *testing.T, kubeclient operatorclient.ClientInterface, c
215217
},
216218
}
217219

220+
prefixFunc := func(s string) string {
221+
return fmt.Sprintf("%s-%s-", prefix, s)
222+
}
223+
218224
// Create CSV
219-
packageName := genName("nginx-")
225+
packageName := genName(prefixFunc("package"))
220226
stableChannel := "stable"
221227

222-
permissions := deploymentPermissions(t)
223-
namedStrategy := newNginxInstallStrategy(genName("dep-"), permissions, nil)
228+
namedStrategy := newNginxInstallStrategy(genName(prefixFunc("dep")), permissions, nil)
224229
csvA := newCSV("nginx-a", namespace, "", semver.MustParse("0.1.0"), []apiextensions.CustomResourceDefinition{crd}, nil, namedStrategy)
225230
csvB := newCSV("nginx-b", namespace, "nginx-a", semver.MustParse("0.2.0"), []apiextensions.CustomResourceDefinition{crd}, nil, namedStrategy)
226231

@@ -235,7 +240,7 @@ func newCatalogSource(t *testing.T, kubeclient operatorclient.ClientInterface, c
235240
},
236241
}
237242

238-
catalogSourceName := genName("mock-nginx-")
243+
catalogSourceName := genName(prefixFunc("catsrc"))
239244
catsrc, cleanup = createInternalCatalogSource(t, kubeclient, crclient, catalogSourceName, namespace, manifests, []apiextensions.CustomResourceDefinition{crd}, []v1alpha1.ClusterServiceVersion{csvA, csvB})
240245
require.NotNil(t, catsrc)
241246
require.NotNil(t, cleanup)

0 commit comments

Comments
 (0)