Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/gitops/utils/gitops.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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');
});
});
4 changes: 2 additions & 2 deletions src/gitops/utils/gitops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading