diff --git a/src/gitops/utils/gitops.test.ts b/src/gitops/utils/gitops.test.ts index 24e9b2aff..6bd75d0fe 100644 --- a/src/gitops/utils/gitops.test.ts +++ b/src/gitops/utils/gitops.test.ts @@ -118,6 +118,27 @@ describe('getOperationType', () => { }); }); +const healthyApplicationSetConditions = [ + { + type: 'ErrorOccurred', + status: 'False', + reason: 'ApplicationSetUpToDate', + message: 'All applications have been generated successfully', + }, + { + type: 'ParametersGenerated', + status: 'True', + reason: 'ParametersGenerated', + message: 'Successfully generated parameters for all Applications', + }, + { + type: 'ResourcesUpToDate', + status: 'True', + reason: 'ApplicationSetUpToDate', + message: 'All applications have been generated successfully', + }, +]; + describe('getAppSetStatus', () => { it('determines ApplicationSet status', () => { expect( @@ -140,4 +161,34 @@ describe('getAppSetStatus', () => { expect(getAppSetStatus({} as any)).toMatchInlineSnapshot(`"Unknown"`); }); + + it('returns Healthy for realistic upstream conditions (ResourcesUpToDate=True)', () => { + expect( + getAppSetStatus({ + status: { conditions: healthyApplicationSetConditions }, + } as any), + ).toBe('Healthy'); + }); + + it('returns Error when ResourcesUpToDate is False', () => { + expect( + getAppSetStatus({ + status: { + conditions: [ + { type: 'ErrorOccurred', status: 'False' }, + { type: 'ParametersGenerated', status: 'True' }, + { type: 'ResourcesUpToDate', status: 'False', reason: 'ErrorOccurred' }, + ], + }, + } as any), + ).toBe('Error'); + }); + + it('does not treat ApplicationSetUpToDate reason as a condition type', () => { + expect( + getAppSetStatus({ + status: { conditions: [{ type: 'ApplicationSetUpToDate', status: 'True' }] }, + } as any), + ).toBe('Healthy'); + }); }); diff --git a/src/gitops/utils/gitops.ts b/src/gitops/utils/gitops.ts index 7457e09e5..78218f953 100644 --- a/src/gitops/utils/gitops.ts +++ b/src/gitops/utils/gitops.ts @@ -192,8 +192,8 @@ export function getAppSetStatus(appset: ApplicationSetKind): ApplicationSetStatu ) { status = ApplicationSetStatus.ERROR; } else if ( - condition.type == 'ApplicationSetUpToDate' && - condition.status == K8sResourceConditionStatus.True + condition.type == 'ResourcesUpToDate' && + condition.status != K8sResourceConditionStatus.True ) { status = ApplicationSetStatus.ERROR; }