Skip to content

Commit 82fbd6e

Browse files
Fix config connector healthcheck race condition with observedGeneration, add generation tests
Signed-off-by: danko <[email protected]>
1 parent 23f3472 commit 82fbd6e

File tree

127 files changed

+953
-360
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+953
-360
lines changed

resource_customizations/cloudfunctions.cnrm.cloud.google.com/CloudFunctionsFunction/health.lua

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,38 @@ local hs = {
44
}
55
if obj.status ~= nil then
66
if obj.status.conditions ~= nil then
7-
for i, condition in ipairs(obj.status.conditions) do
7+
8+
-- Don't change health if the resource status is stale, skip if observedGeneration is not set
9+
if obj.status.observedGeneration == nil or obj.status.observedGeneration == obj.metadata.generation then
10+
for i, condition in ipairs(obj.status.conditions) do
811

9-
-- Up To Date
10-
if condition.reason == "UpToDate" and condition.status == "True" then
11-
hs.status = "Healthy"
12-
hs.message = condition.message
13-
return hs
14-
end
12+
-- Up To Date
13+
if condition.reason == "UpToDate" and condition.status == "True" then
14+
hs.status = "Healthy"
15+
hs.message = condition.message
16+
return hs
17+
end
1518

16-
-- Update Failed
17-
if condition.reason == "UpdateFailed" then
18-
hs.status = "Degraded"
19-
hs.message = condition.message
20-
return hs
21-
end
19+
-- Update Failed
20+
if condition.reason == "UpdateFailed" then
21+
hs.status = "Degraded"
22+
hs.message = condition.message
23+
return hs
24+
end
2225

23-
-- Dependency Not Found
24-
if condition.reason == "DependencyNotFound" then
25-
hs.status = "Degraded"
26-
hs.message = condition.message
27-
return hs
28-
end
26+
-- Dependency Not Found
27+
if condition.reason == "DependencyNotFound" then
28+
hs.status = "Degraded"
29+
hs.message = condition.message
30+
return hs
31+
end
2932

30-
-- Dependency Not Ready
31-
if condition.reason == "DependencyNotReady" then
32-
hs.status = "Suspended"
33-
hs.message = condition.message
34-
return hs
33+
-- Dependency Not Ready
34+
if condition.reason == "DependencyNotReady" then
35+
hs.status = "Suspended"
36+
hs.message = condition.message
37+
return hs
38+
end
3539
end
3640
end
3741
end

resource_customizations/cloudfunctions.cnrm.cloud.google.com/CloudFunctionsFunction/health_test.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ tests:
1919
status: Progressing
2020
message: "Update in progress"
2121
inputPath: testdata/update_in_progress.yaml
22+
- healthStatus:
23+
status: Progressing
24+
message: 'Update in progress'
25+
inputPath: testdata/generation.yaml

resource_customizations/cloudfunctions.cnrm.cloud.google.com/CloudFunctionsFunction/testdata/dependency_not_found.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
apiVersion: cloudfunctions.cnrm.cloud.google.com/v1beta1
22
kind: CloudFunctionsFunction
3+
metadata:
4+
generation: 1
35
status:
6+
observedGeneration: 1
47
conditions:
58
- lastTransitionTime: '2022-07-01T12:56:21Z'
69
message: Dependency not found

resource_customizations/cloudfunctions.cnrm.cloud.google.com/CloudFunctionsFunction/testdata/dependency_not_ready.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
apiVersion: cloudfunctions.cnrm.cloud.google.com/v1beta1
22
kind: CloudFunctionsFunction
3+
metadata:
4+
generation: 1
35
status:
6+
observedGeneration: 1
47
conditions:
58
- lastTransitionTime: '2022-07-01T12:56:21Z'
69
message: Dependency not ready
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: cloudfunctions.cnrm.cloud.google.com/v1beta1
2+
kind: CloudFunctionsFunction
3+
metadata:
4+
generation: 2
5+
status:
6+
observedGeneration: 1
7+
conditions:
8+
- lastTransitionTime: '2022-05-09T08:49:18Z'
9+
message: The resource is up to date
10+
reason: UpToDate
11+
status: 'True'
12+
type: Ready

resource_customizations/cloudfunctions.cnrm.cloud.google.com/CloudFunctionsFunction/testdata/up_to_date.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
apiVersion: cloudfunctions.cnrm.cloud.google.com/v1beta1
22
kind: CloudFunctionsFunction
3+
metadata:
4+
generation: 1
35
status:
6+
observedGeneration: 1
47
conditions:
58
- lastTransitionTime: '2022-05-09T08:49:18Z'
69
message: The resource is up to date

resource_customizations/cloudfunctions.cnrm.cloud.google.com/CloudFunctionsFunction/testdata/update_failed.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
apiVersion: cloudfunctions.cnrm.cloud.google.com/v1beta1
22
kind: CloudFunctionsFunction
3+
metadata:
4+
generation: 1
35
status:
6+
observedGeneration: 1
47
conditions:
58
- lastTransitionTime: '2022-07-01T12:56:21Z'
69
message: Update failed

resource_customizations/cloudscheduler.cnrm.cloud.google.com/CloudSchedulerJob/health.lua

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,38 @@ local hs = {
44
}
55
if obj.status ~= nil then
66
if obj.status.conditions ~= nil then
7-
for i, condition in ipairs(obj.status.conditions) do
7+
8+
-- Don't change health if the resource status is stale, skip if observedGeneration is not set
9+
if obj.status.observedGeneration == nil or obj.status.observedGeneration == obj.metadata.generation then
10+
for i, condition in ipairs(obj.status.conditions) do
811

9-
-- Up To Date
10-
if condition.reason == "UpToDate" and condition.status == "True" then
11-
hs.status = "Healthy"
12-
hs.message = condition.message
13-
return hs
14-
end
12+
-- Up To Date
13+
if condition.reason == "UpToDate" and condition.status == "True" then
14+
hs.status = "Healthy"
15+
hs.message = condition.message
16+
return hs
17+
end
1518

16-
-- Update Failed
17-
if condition.reason == "UpdateFailed" then
18-
hs.status = "Degraded"
19-
hs.message = condition.message
20-
return hs
21-
end
19+
-- Update Failed
20+
if condition.reason == "UpdateFailed" then
21+
hs.status = "Degraded"
22+
hs.message = condition.message
23+
return hs
24+
end
2225

23-
-- Dependency Not Found
24-
if condition.reason == "DependencyNotFound" then
25-
hs.status = "Degraded"
26-
hs.message = condition.message
27-
return hs
28-
end
26+
-- Dependency Not Found
27+
if condition.reason == "DependencyNotFound" then
28+
hs.status = "Degraded"
29+
hs.message = condition.message
30+
return hs
31+
end
2932

30-
-- Dependency Not Ready
31-
if condition.reason == "DependencyNotReady" then
32-
hs.status = "Suspended"
33-
hs.message = condition.message
34-
return hs
33+
-- Dependency Not Ready
34+
if condition.reason == "DependencyNotReady" then
35+
hs.status = "Suspended"
36+
hs.message = condition.message
37+
return hs
38+
end
3539
end
3640
end
3741
end

resource_customizations/cloudscheduler.cnrm.cloud.google.com/CloudSchedulerJob/health_test.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ tests:
1919
status: Progressing
2020
message: "Update in progress"
2121
inputPath: testdata/update_in_progress.yaml
22+
- healthStatus:
23+
status: Progressing
24+
message: 'Update in progress'
25+
inputPath: testdata/generation.yaml

resource_customizations/cloudscheduler.cnrm.cloud.google.com/CloudSchedulerJob/testdata/dependency_not_found.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
apiVersion: cloudscheduler.cnrm.cloud.google.com/v1beta1
22
kind: CloudSchedulerJob
3+
metadata:
4+
generation: 1
35
status:
6+
observedGeneration: 1
47
conditions:
58
- lastTransitionTime: '2022-07-01T12:56:21Z'
69
message: Dependency not found

0 commit comments

Comments
 (0)