Skip to content

Commit a02a5b8

Browse files
fix: resource check for argocd controller (#1836)
Co-authored-by: jeho <[email protected]>
1 parent de56ccb commit a02a5b8

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

src/common/k8s.test.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,11 @@ describe('StatefulSet tests', () => {
160160
),
161161
).resolves.not.toThrow()
162162

163-
expect(debug).toHaveBeenNthCalledWith(1, 'sts/argocd-application-controller pod has not desired resources')
164163
expect(debug).toHaveBeenNthCalledWith(
165-
2,
164+
1,
166165
'sts/argocd-application-controller has been patched with resources: {"requests":{"cpu":"500m","memory":"1Gi"},"limits":{"cpu":"1","memory":"2Gi"}}',
167166
)
168-
expect(debug).toHaveBeenNthCalledWith(3, 'sts/argocd-application-controller pods restarted')
167+
expect(debug).toHaveBeenNthCalledWith(2, 'sts/argocd-application-controller pods restarted')
169168
})
170169

171170
it('should log an error if no pods are found', async () => {
@@ -218,7 +217,7 @@ describe('StatefulSet tests', () => {
218217
mockDebugger,
219218
)
220219

221-
expect(debug).toBeCalledTimes(0)
220+
expect(debug).toBeCalledTimes(1)
222221
})
223222

224223
it('should log an error if an exception occurs', async () => {

src/common/k8s.ts

+16-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { AnyAaaaRecord, AnyARecord } from 'dns'
55
import { resolveAny } from 'dns/promises'
66
import { access, mkdir, writeFile } from 'fs/promises'
77
import { Agent } from 'https'
8-
import { isEmpty, map, mapValues } from 'lodash'
8+
import { isEmpty, isEqual, map, mapValues } from 'lodash'
99
import fetch, { RequestInit } from 'node-fetch'
1010
import { dirname, join } from 'path'
1111
import { parse, stringify } from 'yaml'
@@ -371,15 +371,23 @@ export async function patchContainerResourcesOfSts(
371371
for (const pod of pods.items) {
372372
const actualResources = pod.spec?.containers?.find((container) => container.name === containerName)?.resources
373373

374-
if (actualResources != desiredResources) {
375-
d.info(`sts/argocd-application-controller pod has not desired resources`)
374+
if (
375+
isEqual(actualResources?.limits, desiredResources?.limits) &&
376+
isEqual(actualResources?.requests, desiredResources?.requests)
377+
) {
378+
d.info(
379+
`sts/argocd-application-controller pod has desired resources: ${JSON.stringify(
380+
desiredResources,
381+
)} and actual resources: ${JSON.stringify(actualResources)}`,
382+
)
383+
return
384+
}
376385

377-
await patchStatefulSetResources(statefulSetName, containerName, namespace, desiredResources, appsApi, d)
378-
d.info(`sts/argocd-application-controller has been patched with resources: ${JSON.stringify(desiredResources)}`)
386+
await patchStatefulSetResources(statefulSetName, containerName, namespace, desiredResources, appsApi, d)
387+
d.info(`sts/argocd-application-controller has been patched with resources: ${JSON.stringify(desiredResources)}`)
379388

380-
await deleteStatefulSetPods(statefulSetName, namespace, appsApi, coreApi, d)
381-
d.info(`sts/argocd-application-controller pods restarted`)
382-
}
389+
await deleteStatefulSetPods(statefulSetName, namespace, appsApi, coreApi, d)
390+
d.info(`sts/argocd-application-controller pods restarted`)
383391
}
384392
} catch (error) {
385393
d.error(`Error patching StatefulSet ${statefulSetName}:`, error)

0 commit comments

Comments
 (0)