11hs = {}
2- if obj .status ~= nil then
3- if obj .status .conditions ~= nil then
4- for i , condition in ipairs (obj .status .conditions ) do
5- if condition .type == " Progressing" and condition .status == " False" then
6- hs .status = " Degraded"
7- hs .message = condition .message
8- return hs
9- end
10- if condition .type == " Available" and condition .status == " True" then
11- hs .status = " Healthy"
12- hs .message = condition .message
13- return hs
14- end
2+
3+ -- Check if status exists
4+ if not obj .status then
5+ hs .status = " Degraded"
6+ hs .message = " No status available"
7+ return hs
8+ end
9+
10+ -- Initialize variables for conditions
11+ local available = false
12+ local progressing = false
13+ local availableMessage = " "
14+ local progressingMessage = " "
15+
16+ -- Check conditions
17+ if obj .status .conditions then
18+ for _ , condition in ipairs (obj .status .conditions ) do
19+ if condition .type == " Available" then
20+ available = condition .status == " True"
21+ availableMessage = condition .message or " Application availability status"
22+ elseif condition .type == " Progressing" then
23+ progressing = condition .status == " True"
24+ progressingMessage = condition .message or " Application progress status"
1525 end
1626 end
1727end
1828
19- hs .status = " Progressing"
20- hs .message = " Waiting for SpinApp to be available"
29+ -- Check ready replicas if specified
30+ local readyReplicas = obj .status .readyReplicas or 0
31+ local desiredReplicas = obj .spec .replicas or 1
32+
33+ -- Determine status based on conditions
34+ if not available then
35+ hs .status = " Degraded"
36+ hs .message = availableMessage or " Application is not available"
37+ return hs
38+ end
39+
40+ if readyReplicas < desiredReplicas then
41+ hs .status = " Progressing"
42+ hs .message = string.format (" Waiting for replicas to be ready (%d/%d)" , readyReplicas , desiredReplicas )
43+ return hs
44+ end
45+
46+ if progressing then
47+ hs .status = " Progressing"
48+ hs .message = progressingMessage or " Application is still progressing"
49+ return hs
50+ end
51+
52+ -- All checks passed
53+ hs .status = " Healthy"
54+ hs .message = string.format (" Application is healthy with %d/%d replicas ready" , readyReplicas , desiredReplicas )
55+
2156return hs
0 commit comments