@@ -4,44 +4,125 @@ metadata:
44 name : integration-and-unit-tests
55 namespace : multiarch-tuning-ope-tenant
66spec :
7- params : [ ]
7+ params :
8+ - name : SNAPSHOT
9+ description : ' Snapshot of the application'
10+ type : string
11+ default : ' {"components": [{"name":"multiarch-tuning-operator", "containerImage": "quay.io/example/repo:latest"}]}'
812 tasks :
913 - name : clone-and-test
14+ params :
15+ - name : SNAPSHOT
16+ value : $(params.SNAPSHOT)
1017 taskSpec :
18+ params :
19+ - name : SNAPSHOT
20+ type : string
1121 volumes :
1222 - name : source
1323 emptyDir : { }
1424 steps :
1525 - image : brew.registry.redhat.io/rh-osbs/openshift-golang-builder:rhel_9_1.25
1626 env :
17- - name : URL
18- valueFrom :
19- fieldRef :
20- fieldPath : metadata.annotations['pac.test.appstudio.openshift.io/source-repo-url']
21- - name : REVISION
22- valueFrom :
23- fieldRef :
24- fieldPath : metadata.annotations['pac.test.appstudio.openshift.io/sha']
27+ - name : SNAPSHOT
28+ value : $(params.SNAPSHOT)
2529 computeResources :
2630 limits :
2731 cpu : 8
28- memory : 4Gi
32+ memory : 8Gi
2933 requests :
3034 cpu : 500m
31- memory : 1Gi
35+ memory : 2Gi
3236 volumeMounts :
3337 - name : source
3438 mountPath : /workspace
3539 script : |
3640 #!/bin/bash
3741 set -exuo pipefail
42+
43+ echo "Debug: SNAPSHOT content:"
44+ echo "${SNAPSHOT}"
45+
46+ # Parse JSON using Python (available in golang-builder image)
47+ read -r URL REVISION <<< $(python3 -c "
48+ import json, sys
49+ snapshot = json.loads('''${SNAPSHOT}''')
50+ components = snapshot.get('components', [])
51+ if components:
52+ comp = components[0]
53+ # Try source.git first (newer format)
54+ url = comp.get('source', {}).get('git', {}).get('url', '')
55+ rev = comp.get('source', {}).get('git', {}).get('revision', '')
56+ # Fallback to top-level fields
57+ if not url:
58+ url = comp.get('repository', '')
59+ if not rev:
60+ rev = comp.get('revision', '')
61+ print(url, rev)
62+ ")
63+
64+ # If not in SNAPSHOT param, try to fetch from Snapshot resource (for group tests)
3865 if [ -z "$URL" ] || [ -z "$REVISION" ]; then
39- echo "URL and REVISION must be set"
66+ echo "Git info not in SNAPSHOT parameter, trying Snapshot resource..."
67+
68+ # Try to get snapshot name from the SNAPSHOT parameter
69+ SNAPSHOT_NAME=$(python3 -c "
70+ import json
71+ try:
72+ snapshot = json.loads('''${SNAPSHOT}''')
73+ print(snapshot.get('application', ''))
74+ except: pass
75+ " 2>/dev/null || echo "")
76+
77+ # If we have a snapshot name, fetch it
78+ if [ -n "$SNAPSHOT_NAME" ]; then
79+ echo "Fetching Snapshot resource: $SNAPSHOT_NAME"
80+
81+ # Install oc/kubectl if not available
82+ if ! command -v oc &> /dev/null && ! command -v kubectl &> /dev/null; then
83+ echo "Installing oc client..."
84+ curl -sL https://mirror.openshift.com/pub/openshift-v4/clients/ocp/stable/openshift-client-linux.tar.gz | tar -xzf - -C /usr/local/bin/ oc
85+ chmod +x /usr/local/bin/oc
86+ fi
87+
88+ # Use oc if available, otherwise kubectl
89+ K8S_CMD=$(command -v oc || command -v kubectl)
90+
91+ # Fetch snapshot and extract git info (try current namespace)
92+ SNAPSHOT_JSON=$($K8S_CMD get snapshot "$SNAPSHOT_NAME" -o json 2>/dev/null || echo "")
93+
94+ if [ -n "$SNAPSHOT_JSON" ]; then
95+ read -r URL REVISION <<< $(echo "$SNAPSHOT_JSON" | python3 -c "
96+ import json, sys
97+ try:
98+ snapshot = json.load(sys.stdin)
99+ components = snapshot.get('spec', {}).get('components', [])
100+ for comp in components:
101+ # Look for multiarch-tuning-operator component
102+ if 'multiarch-tuning-operator' in comp.get('name', ''):
103+ url = comp.get('source', {}).get('git', {}).get('url', '')
104+ rev = comp.get('source', {}).get('git', {}).get('revision', '')
105+ if url and rev:
106+ print(url, rev)
107+ break
108+ except: pass
109+ ")
110+ fi
111+ fi
112+ fi
113+
114+ if [ -z "$URL" ] || [ -z "$REVISION" ]; then
115+ echo "ERROR: Could not extract git URL and revision"
116+ echo "Tried SNAPSHOT parameter and Snapshot resource"
117+ echo "SNAPSHOT content was:"
118+ echo "${SNAPSHOT}"
40119 exit 1
41120 fi
42- echo "Initializing the env vars"
121+
122+ echo "Successfully extracted git info:"
43123 echo "URL: $URL"
44124 echo "REVISION: $REVISION"
125+
45126 mkdir /workspace/source
46127 cd /workspace/source
47128 git init
0 commit comments