Skip to content

Commit cd75a12

Browse files
committed
test: fix openshift4 flakes
1 parent e26ad5c commit cd75a12

File tree

5 files changed

+39
-6
lines changed

5 files changed

+39
-6
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ jobs:
392392
openshift4_integration_tests:
393393
machine:
394394
docker_layer_caching: true
395-
image: ubuntu-2004:202111-02
395+
image: ubuntu-2204:current
396396
resource_class: large
397397
steps:
398398
- checkout

.circleci/config/jobs/openshift4_integration_tests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
machine:
22
resource_class: large
3-
image: ubuntu-2004:202111-02
3+
# https://circleci.com/developer/machine/image/ubuntu-2204
4+
image: ubuntu-2204:current
45
docker_layer_caching: true
56
working_directory: ~/kubernetes-monitor
67
steps:

test/setup/deployers/operator-openshift.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import sleep from 'sleep-promise';
12
import { readFileSync, writeFileSync } from 'fs';
23
import { parse, stringify } from 'yaml';
34
import { IDeployer, IImageOptions } from './types';
45
import * as kubectl from '../../helpers/kubectl';
6+
import { execWrapper as exec } from '../../helpers/exec';
57

68
export const operatorDeployer: IDeployer = {
79
deploy: deployKubernetesMonitor,
@@ -17,10 +19,27 @@ async function deployKubernetesMonitor(
1719
await kubectl.applyK8sYaml('./test/fixtures/operator/installation.yaml');
1820
// Await for the Operator to become available, only then
1921
// the Operator can start processing the custom resource.
20-
await kubectl.waitForDeployment('snyk-operator', 'snyk-monitor');
22+
await deploymentIsReady('snyk-operator', 'snyk-monitor');
2123
await kubectl.applyK8sYaml('./test/fixtures/operator/custom-resource.yaml');
2224
}
2325

26+
async function deploymentIsReady(
27+
name: string,
28+
namespace: string,
29+
): Promise<boolean> {
30+
for (let attempt = 0; attempt < 180; attempt++) {
31+
try {
32+
await exec(`./kubectl get deployment.apps/${name} -n ${namespace}`);
33+
// Give the deployment enough time to settle and apply the CRD
34+
await sleep(60_000);
35+
return true;
36+
} catch (error) {
37+
await sleep(1000);
38+
}
39+
}
40+
return false;
41+
}
42+
2443
function createTestOperatorSource(newYamlPath: string): void {
2544
console.log('Creating YAML CatalogSource...');
2645
const operatorVersion =

test/setup/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,16 @@ export async function deployMonitor(): Promise<string> {
196196
pullPolicy: imagePullPolicy,
197197
};
198198
await deployers[deploymentType].deploy(deploymentImageOptions);
199-
await kubectl.waitForDeployment('snyk-monitor', namespace);
199+
for (let attempt = 0; attempt < 180; attempt++) {
200+
try {
201+
await exec(
202+
`./kubectl get deployment.apps/snyk-monitor -n ${namespace}`,
203+
);
204+
break;
205+
} catch {
206+
await sleep(1000);
207+
}
208+
}
200209

201210
console.log(
202211
`Deployed the snyk-monitor with integration ID ${integrationId}`,

test/setup/platforms/openshift4.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,14 @@ export async function clean(): Promise<void> {
152152
.deleteResource('--all', 'all,sa,cm,secret,pvc,rollouts', 'services')
153153
.catch(() => undefined),
154154
kubectl
155-
.deleteResource('--all', 'all,sa,cm,secret,pvc', 'argo-rollout')
155+
.deleteResource('--all', 'all,sa,cm,secret,pvc,rollouts', 'argo-rollouts')
156156
.catch(() => undefined),
157157
kubectl
158-
.deleteResource('--all', 'all,sa,cm,secret,pvc', 'snyk-monitor')
158+
.deleteResource(
159+
'--all',
160+
'all,sa,cm,secret,pvc,subscription,installplan,csv',
161+
'snyk-monitor',
162+
)
159163
.catch(() => undefined),
160164
]);
161165

0 commit comments

Comments
 (0)