Skip to content

Commit 5df0002

Browse files
committed
Added test for cronjob and scaledjob image substitution
1 parent 198d935 commit 5df0002

5 files changed

Lines changed: 285 additions & 3 deletions

File tree

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
name: Image Substitution Integration Test
2+
3+
on:
4+
push:
5+
branches: [main, develop]
6+
pull_request:
7+
branches: [main]
8+
workflow_dispatch:
9+
10+
env:
11+
REGISTRY: asia-south1-docker.pkg.dev
12+
PROJECT_ID: test-project
13+
REPOSITORY: test-repo
14+
15+
jobs:
16+
test-current-version:
17+
runs-on: ubuntu-latest
18+
name: Test Current Version (Should Work)
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
24+
- name: Set up Node.js
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: '18'
28+
cache: 'npm'
29+
30+
- name: Install dependencies and build
31+
run: |
32+
npm ci
33+
npm run build
34+
35+
- name: Create fake kubeconfig
36+
run: |
37+
mkdir -p ~/.kube
38+
cat << EOF > ~/.kube/config
39+
apiVersion: v1
40+
kind: Config
41+
clusters:
42+
- cluster:
43+
server: https://fake-cluster.example.com
44+
name: fake-cluster
45+
contexts:
46+
- context:
47+
cluster: fake-cluster
48+
user: fake-user
49+
name: fake-context
50+
current-context: fake-context
51+
users:
52+
- name: fake-user
53+
user:
54+
token: fake-token
55+
EOF
56+
57+
- name: Deploy CronJob with current version
58+
id: cronjob-current
59+
continue-on-error: true
60+
uses: ./
61+
with:
62+
action: deploy
63+
namespace: default
64+
manifests: |
65+
test/integration/manifests/test-cronjob.yaml
66+
images: |
67+
asia-south1-docker.pkg.dev/project/repo/image:${{ github.sha }}
68+
69+
- name: Deploy ScaledJob with current version
70+
id: scaledjob-current
71+
continue-on-error: true
72+
uses: ./
73+
with:
74+
action: deploy
75+
namespace: default
76+
manifests: |
77+
test/integration/manifests/test-scaledjob.yaml
78+
images: |
79+
asia-south1-docker.pkg.dev/project/repo/image:${{ github.sha }}
80+
81+
- name: Verify current version results
82+
run: |
83+
echo "Current version test results:"
84+
echo "CronJob outcome: ${{ steps.cronjob-current.outcome }}"
85+
echo "ScaledJob outcome: ${{ steps.scaledjob-current.outcome }}"
86+
87+
# Both should fail due to fake kubectl, but they should process the manifests
88+
if [[ "${{ steps.cronjob-current.outcome }}" == "failure" && "${{ steps.scaledjob-current.outcome }}" == "failure" ]]; then
89+
echo "✅ Current version processed both CronJob and ScaledJob (kubectl failures expected)"
90+
else
91+
echo "❌ Unexpected outcomes with current version"
92+
exit 1
93+
fi
94+
95+
test-old-version:
96+
runs-on: ubuntu-latest
97+
name: Test Old Version v5.0.3 (Should Fail on ScaledJob)
98+
99+
steps:
100+
- name: Checkout repository
101+
uses: actions/checkout@v4
102+
103+
- name: Create fake kubeconfig
104+
run: |
105+
mkdir -p ~/.kube
106+
cat << EOF > ~/.kube/config
107+
apiVersion: v1
108+
kind: Config
109+
clusters:
110+
- cluster:
111+
server: https://fake-cluster.example.com
112+
name: fake-cluster
113+
contexts:
114+
- context:
115+
cluster: fake-cluster
116+
user: fake-user
117+
name: fake-context
118+
current-context: fake-context
119+
users:
120+
- name: fake-user
121+
user:
122+
token: fake-token
123+
EOF
124+
125+
- name: Deploy CronJob with old version v5.0.3
126+
id: cronjob-old
127+
continue-on-error: true
128+
uses: azure/k8s-deploy@v5.0.3
129+
with:
130+
action: deploy
131+
namespace: default
132+
manifests: |
133+
test/integration/manifests/test-cronjob.yaml
134+
images: |
135+
asia-south1-docker.pkg.dev/project/repo/image:${{ github.sha }}
136+
137+
- name: Deploy ScaledJob with old version v5.0.3
138+
id: scaledjob-old
139+
continue-on-error: true
140+
uses: azure/k8s-deploy@v5.0.3
141+
with:
142+
action: deploy
143+
namespace: default
144+
manifests: |
145+
test/integration/manifests/test-scaledjob.yaml
146+
images: |
147+
asia-south1-docker.pkg.dev/project/repo/image:${{ github.sha }}
148+
149+
- name: Verify old version results
150+
run: |
151+
echo "Old version test results:"
152+
echo "CronJob outcome: ${{ steps.cronjob-old.outcome }}"
153+
echo "ScaledJob outcome: ${{ steps.scaledjob-old.outcome }}"
154+
155+
# CronJob should work (kubectl failure), ScaledJob should fail earlier due to unsupported type
156+
if [[ "${{ steps.cronjob-old.outcome }}" == "failure" ]]; then
157+
echo "✅ Old version processed CronJob (kubectl failure expected)"
158+
else
159+
echo "❌ Old version CronJob had unexpected outcome"
160+
fi
161+
162+
if [[ "${{ steps.scaledjob-old.outcome }}" == "failure" ]]; then
163+
echo "✅ Old version failed on ScaledJob as expected (unsupported workload type)"
164+
else
165+
echo "❌ Old version should have failed on ScaledJob"
166+
exit 1
167+
fi
168+
169+
echo "🎉 Version comparison test completed successfully!"
170+
171+
- name: Cleanup
172+
if: always()
173+
run: |
174+
echo "✅ Test completed - no cleanup needed"

src/utilities/fileUtils.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('File utils', () => {
4949
'test/unit/manifests/basic-test.yml'
5050
]
5151

52-
expect(testSearch).toHaveLength(9)
52+
expect(testSearch).toHaveLength(10)
5353
expectedManifests.forEach((fileName) => {
5454
if (fileName.startsWith('test/unit')) {
5555
expect(testSearch).toContain(fileName)
@@ -95,7 +95,7 @@ describe('File utils', () => {
9595
fileAtOuter,
9696
innerPath
9797
])
98-
).toHaveLength(8)
98+
).toHaveLength(9)
9999
})
100100

101101
it('throws an error for an invalid URL', async () => {

src/utilities/manifestUpdateUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export function getReplicaCount(inputObject: any): any {
152152
throw InputObjectKindNotDefinedError
153153
}
154154

155-
const {kind} = inputObject.kind.toLowerCase()
155+
const kind = inputObject.kind.toLowerCase()
156156

157157
const workloadsWithReplicas = new Set([
158158
KubernetesWorkload.DEPLOYMENT.toLowerCase(),
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
apiVersion: batch/v1
2+
kind: CronJob
3+
metadata:
4+
name: integration-test-cronjob
5+
namespace: default
6+
labels:
7+
app: integration-test
8+
component: cronjob
9+
spec:
10+
schedule: '0 2 * * *'
11+
jobTemplate:
12+
spec:
13+
template:
14+
metadata:
15+
labels:
16+
app: integration-test
17+
component: batch-processor
18+
spec:
19+
containers:
20+
- name: batch-processor
21+
image: asia-south1-docker.pkg.dev/project/repo/image:latest
22+
command:
23+
- /bin/sh
24+
- -c
25+
- |
26+
echo "Starting batch job at $(date)"
27+
echo "Processing daily batch operations..."
28+
# Simulate batch processing work
29+
for i in $(seq 1 3); do
30+
echo "Processing batch $i"
31+
sleep 1
32+
done
33+
echo "Batch job completed at $(date)"
34+
env:
35+
- name: JOB_TYPE
36+
value: 'batch'
37+
- name: ENVIRONMENT
38+
value: 'integration-test'
39+
resources:
40+
requests:
41+
memory: '64Mi'
42+
cpu: '50m'
43+
limits:
44+
memory: '128Mi'
45+
cpu: '100m'
46+
restartPolicy: OnFailure
47+
successfulJobsHistoryLimit: 3
48+
failedJobsHistoryLimit: 1
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
apiVersion: keda.sh/v1alpha1
2+
kind: ScaledJob
3+
metadata:
4+
name: integration-test-scaledjob
5+
namespace: default
6+
labels:
7+
app: integration-test
8+
component: scaledjob
9+
spec:
10+
jobTemplate:
11+
spec:
12+
template:
13+
metadata:
14+
labels:
15+
app: integration-test
16+
component: scaledjob-processor
17+
spec:
18+
containers:
19+
- name: processor
20+
image: asia-south1-docker.pkg.dev/project/repo/image:latest
21+
command:
22+
- /bin/sh
23+
- -c
24+
- |
25+
echo "Starting scaled job processor at $(date)"
26+
echo "Processing queue items..."
27+
# Simulate processing work
28+
for i in $(seq 1 5); do
29+
echo "Processing item $i"
30+
sleep 2
31+
done
32+
echo "Scaled job completed at $(date)"
33+
env:
34+
- name: JOB_TYPE
35+
value: 'scaled'
36+
- name: BATCH_SIZE
37+
value: '10'
38+
resources:
39+
requests:
40+
memory: '128Mi'
41+
cpu: '100m'
42+
limits:
43+
memory: '256Mi'
44+
cpu: '200m'
45+
restartPolicy: OnFailure
46+
triggers:
47+
- type: cron
48+
metadata:
49+
timezone: Etc/UTC
50+
start: 0 3 * * *
51+
end: 0 4 * * *
52+
- type: rabbitmq
53+
metadata:
54+
host: rabbitmq-service.default.svc.cluster.local:5672
55+
queueName: work-queue
56+
queueLength: '5'
57+
minReplicaCount: 0
58+
maxReplicaCount: 10
59+
successfulJobsHistoryLimit: 5
60+
failedJobsHistoryLimit: 2

0 commit comments

Comments
 (0)