Skip to content

Commit 7e7db64

Browse files
raisavarghesexinredhatjkopriva
authored
RHTAP-2549 Verify the RH syft image path in automation (#167)
* RHTAP-2549 [e2e-tests] CLIs Automation: TPA: Check RH Syft, download of CLI * Updated code according to --------- Co-authored-by: Xin Jiang <[email protected]> Co-authored-by: Josef Kopriva <[email protected]>
1 parent c4adb0e commit 7e7db64

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

src/apis/kubernetes/kube.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CoreV1Api, CustomObjectsApi, KubeConfig, V1ObjectMeta } from "@kubernetes/client-node";
1+
import { CoreV1Api, CustomObjectsApi, dumpYaml, KubeConfig, loadYaml, V1ObjectMeta } from "@kubernetes/client-node";
22
import { PipelineRunKind, TaskRunKind } from '@janus-idp/shared-react';
33
import * as path from "node:path";
44
import { Utils } from "../git-providers/utils";
@@ -220,6 +220,30 @@ export class Kubernetes extends Utils {
220220
throw new Error(`Timeout reached waiting for pipeline run '${name}' to finish.`);
221221
}
222222

223+
/**
224+
* Accepts the pipelinerun name and fetches pipelinerun yaml output.
225+
* Returns the yaml value in the variable 'doc'
226+
* @param {string} namespace - The namespace default value is rhtap-app-development.
227+
* @param {string} name - The name of the pipelinerun
228+
* @throws This function does not throw directly, but may throw errors during API calls or retries.
229+
*/
230+
public async pipelinerunfromName(name: string,namespace: string) {
231+
try {
232+
const k8sCoreApi = this.kubeConfig.makeApiClient(CustomObjectsApi);
233+
const plr = await k8sCoreApi.getNamespacedCustomObject(
234+
'tekton.dev',
235+
'v1',
236+
namespace,
237+
'pipelineruns',
238+
name
239+
);
240+
const plr_yaml = dumpYaml(plr.body);
241+
const doc = loadYaml(plr_yaml)
242+
return doc
243+
}
244+
catch (error) { console.error('Error fetching PipelineRuns: ', error); }
245+
}
246+
223247
/**
224248
* Waits for an Argo CD application to become healthy.
225249
*

tests/gpts/github/test-config/github_positive_suite.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,25 @@ export const gitHubBasicGoldenPathTemplateTests = (gptTemplate: string) => {
199199
expect(finished).toBe(true)
200200
}
201201
}, 900000)
202-
202+
203+
/**
204+
* Check if the pipelinerun yaml has the rh-syft image path mentioned
205+
*/
206+
it(`Check ${gptTemplate} pipelinerun yaml has the rh-syft image path`, async ()=> {
207+
const pipelineRun = await kubeClient.getPipelineRunByRepository(repositoryName, 'push')
208+
if (pipelineRun && pipelineRun.metadata && pipelineRun.metadata.name) {
209+
const doc = await kubeClient.pipelinerunfromName(pipelineRun.metadata.name,developmentNamespace)
210+
const index = doc.spec.pipelineSpec.tasks.findIndex(item => item.name === "build-container")
211+
console.log(index)
212+
const regex = new RegExp("registry.redhat.io/rh-syft-tech-preview/syft-rhel9", 'i');
213+
const image_index= (doc.spec.pipelineSpec.tasks[index].taskSpec.steps.findIndex(item => regex.test(item.image)))
214+
if (image_index)
215+
{
216+
console.log("The image path found is " + doc.spec.pipelineSpec.tasks[index].taskSpec.steps[image_index].image )
217+
}
218+
expect(image_index).not.toBe(undefined)
219+
}
220+
}, 900000)
203221

204222
/**
205223
* Deletes created applications

0 commit comments

Comments
 (0)