Skip to content

Commit 2ea4288

Browse files
committed
chore: kubectl describe resources in OS4 tests for diagnosing errors
1 parent 2a10efa commit 2ea4288

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

test/helpers/kubectl.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ export async function deletePod(podName: string, namespace: string) {
117117
console.log(`Deleted pod ${podName}`);
118118
}
119119

120+
export async function describeKubernetesResource(kind: string, name: string, namespace: string): Promise<string> {
121+
const result = await exec(`./kubectl describe ${kind} ${name} -n ${namespace}`);
122+
return result.stdout;
123+
}
124+
120125
export async function getDeploymentJson(deploymentName: string, namespace: string): Promise<any> {
121126
const getDeploymentResult = await exec(`./kubectl get deployment ${deploymentName} -n ${namespace} -o json`);
122127
return JSON.parse(getDeploymentResult.stdout);
@@ -143,7 +148,7 @@ export async function getPodLogs(podName: string, namespace: string): Promise<an
143148

144149
export async function waitForDeployment(name: string, namespace: string): Promise<void> {
145150
console.log(`Trying to find deployment ${name} in namespace ${namespace}`);
146-
for (let attempt = 0; attempt < 60; attempt++) {
151+
for (let attempt = 0; attempt < 120; attempt++) {
147152
try {
148153
await exec(`./kubectl get deployment.apps/${name} -n ${namespace}`);
149154
} catch (error) {

test/setup/platforms/openshift4.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,28 @@ export async function exportKubeConfig(): Promise<void> {
5858
process.env.KUBECONFIG = kubeconfigPath;
5959
}
6060

61+
async function tryDescribingResourceToFile(kind: string, name: string, namespace: string): Promise<void> {
62+
return kubectl.describeKubernetesResource(kind, name, namespace)
63+
.then((description) => {
64+
const fileName = `${kind}-${name}-${namespace}`;
65+
const filePath = process.env.CI
66+
// The directory is generated by CircleCI config (see .circleci/config.yml).
67+
? `/tmp/logs/test/integration/openshift4/${fileName}`
68+
: `${tmpdir()}/${fileName}`;
69+
writeFileSync(filePath, description);
70+
console.log(`Description for ${kind} ${name} is stored in ${filePath}`);
71+
})
72+
.catch(() => console.log(`Could not describe ${kind} ${name} in namespace ${namespace}`));
73+
}
74+
6175
export async function clean(): Promise<void> {
76+
await Promise.all([
77+
tryDescribingResourceToFile('deployment', 'snyk-operator', 'snyk-monitor'),
78+
tryDescribingResourceToFile('deployment', 'snyk-monitor', 'snyk-monitor'),
79+
tryDescribingResourceToFile('operatorsource', 'snyk-operator', 'openshift-marketplace'),
80+
tryDescribingResourceToFile('subscription', 'snyk-operator', 'snyk-monitor'),
81+
]);
82+
6283
// Kubernetes will be stuck trying to delete these resources if we don't clear the finalizers.
6384
await Promise.all([
6485
kubectl.patchResourceFinalizers('customresourcedefinition', 'snykmonitors.charts.helm.k8s.io', 'snyk-monitor').catch(() => undefined),

0 commit comments

Comments
 (0)