-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add custom resource health for flux resources (#19082)
* feat: Add custom resource health for flux resources Signed-off-by: Adrian Berger <adrian.berger@bedag.ch> * chore: Update upgrade docs Signed-off-by: Adrian Berger <adrian.berger@bedag.ch> --------- Signed-off-by: Adrian Berger <adrian.berger@bedag.ch> Signed-off-by: Dan Garfield <dan@codefresh.io> Co-authored-by: Dan Garfield <dan@codefresh.io>
- Loading branch information
1 parent
a06cdb3
commit 824d0dc
Showing
56 changed files
with
1,488 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
resource_customizations/helm.toolkit.fluxcd.io/HelmRelease/health.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
local hs = {} | ||
if obj.status ~= nil then | ||
if obj.status.conditions ~= nil then | ||
local numProgressing = 0 | ||
local numSucceeded = 0 | ||
local message = "" | ||
for _, condition in ipairs(obj.status.conditions) do | ||
if condition.type == "Ready" then | ||
if condition.status == "True" then | ||
numSucceeded = numSucceeded + 1 | ||
elseif condition.status == "Unknown" then | ||
numProgressing = numProgressing + 1 | ||
end | ||
message = condition.reason | ||
elseif condition.type == "Reconciling" and condition.status == "True" then | ||
numProgressing = numProgressing + 1 | ||
elseif condition.type == "Released" or condition.type == "TestSuccess" then | ||
if condition.status == "True" then | ||
numSucceeded = numSucceeded + 1 | ||
end | ||
end | ||
end | ||
if(numProgressing == 2) then | ||
hs.message = message | ||
hs.status = "Progressing" | ||
return hs | ||
elseif(numSucceeded == 2) then | ||
hs.message = message | ||
hs.status = "Healthy" | ||
return hs | ||
else | ||
hs.message = message | ||
hs.status = "Degraded" | ||
return hs | ||
end | ||
end | ||
end | ||
hs.message = "Status unknown" | ||
hs.status = "Progressing" | ||
return hs |
13 changes: 13 additions & 0 deletions
13
resource_customizations/helm.toolkit.fluxcd.io/HelmRelease/health_test.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
tests: | ||
- healthStatus: | ||
status: Progressing | ||
message: Progressing | ||
inputPath: testdata/progressing.yaml | ||
- healthStatus: | ||
status: Degraded | ||
message: RollbackSucceeded | ||
inputPath: testdata/degraded.yaml | ||
- healthStatus: | ||
status: Healthy | ||
message: InstallSucceeded | ||
inputPath: testdata/healthy.yaml |
70 changes: 70 additions & 0 deletions
70
resource_customizations/helm.toolkit.fluxcd.io/HelmRelease/testdata/degraded.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
apiVersion: helm.toolkit.fluxcd.io/v2 | ||
kind: HelmRelease | ||
metadata: | ||
name: podinfo | ||
namespace: default | ||
spec: | ||
interval: 10m | ||
timeout: 5m | ||
chart: | ||
spec: | ||
chart: podinfo | ||
version: '6.5.*' | ||
sourceRef: | ||
kind: HelmRepository | ||
name: podinfo | ||
interval: 5m | ||
releaseName: podinfo | ||
install: | ||
remediation: | ||
retries: 3 | ||
upgrade: | ||
remediation: | ||
retries: 3 | ||
test: | ||
enable: true | ||
driftDetection: | ||
mode: enabled | ||
ignore: | ||
- paths: ["/spec/replicas"] | ||
target: | ||
kind: Deployment | ||
values: | ||
replicaCount: 2 | ||
status: | ||
conditions: | ||
- lastTransitionTime: "2024-07-16T12:00:00Z" | ||
message: Helm rollback to previous release default/podinfo.v24 with | ||
chart podinfo@6.5.4 succeeded | ||
observedGeneration: 5 | ||
reason: ProgressingWithRetry | ||
status: "True" | ||
type: Reconciling | ||
- lastTransitionTime: "2024-07-16T12:00:00Z" | ||
message: Helm rollback to previous release default/podinfo.v24 with | ||
chart podinfo@6.5.4 succeeded | ||
observedGeneration: 5 | ||
reason: RollbackSucceeded | ||
status: "False" | ||
type: Ready | ||
- lastTransitionTime: "2024-07-16T12:00:00Z" | ||
message: "Helm upgrade failed for release default/podinfo with chart | ||
podinfo@6.5.4: cannot patch \"podinfo\" with kind Deployment: admission webhook | ||
\"validate.kyverno.svc-fail\" denied the request: \n\nresource Deployment/default/podinfo | ||
was blocked due to the following policies \n\ndisallow-privilege-escalation:\n | ||
\ autogen-privilege-escalation: 'validation error: Privilege escalation is disallowed.\n | ||
\ The fields spec.containers[*].securityContext.allowPrivilegeEscalation, | ||
spec.initContainers[*].securityContext.allowPrivilegeEscalation,\n and spec.ephemeralContainers[*].securityContext.allowPrivilegeEscalation | ||
must\n be set to `false`. rule autogen-privilege-escalation failed at path | ||
/spec/template/spec/containers/0/securityContext/allowPrivilegeEscalation/'" | ||
observedGeneration: 5 | ||
reason: UpgradeFailed | ||
status: "False" | ||
type: Released | ||
- lastTransitionTime: "2024-07-16T12:00:00Z" | ||
message: Helm rollback to previous release default/podinfo.v24 with | ||
chart podinfo@6.5.4 succeeded | ||
observedGeneration: 5 | ||
reason: RollbackSucceeded | ||
status: "True" | ||
type: Remediated |
49 changes: 49 additions & 0 deletions
49
resource_customizations/helm.toolkit.fluxcd.io/HelmRelease/testdata/healthy.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
apiVersion: helm.toolkit.fluxcd.io/v2 | ||
kind: HelmRelease | ||
metadata: | ||
name: podinfo | ||
namespace: default | ||
spec: | ||
interval: 10m | ||
timeout: 5m | ||
chart: | ||
spec: | ||
chart: podinfo | ||
version: '6.5.*' | ||
sourceRef: | ||
kind: HelmRepository | ||
name: podinfo | ||
interval: 5m | ||
releaseName: podinfo | ||
install: | ||
remediation: | ||
retries: 3 | ||
upgrade: | ||
remediation: | ||
retries: 3 | ||
test: | ||
enable: true | ||
driftDetection: | ||
mode: enabled | ||
ignore: | ||
- paths: ["/spec/replicas"] | ||
target: | ||
kind: Deployment | ||
values: | ||
replicaCount: 2 | ||
status: | ||
conditions: | ||
- lastTransitionTime: "2024-07-16T12:00:00Z" | ||
message: Helm install succeeded for release default/podinfo.v1 with | ||
chart podinfo@6.5.4 | ||
observedGeneration: 2 | ||
reason: InstallSucceeded | ||
status: "True" | ||
type: Ready | ||
- lastTransitionTime: "2024-07-16T12:00:00Z" | ||
message: Helm install succeeded for release default/podinfo.v1 with | ||
chart podinfo@6.5.4 | ||
observedGeneration: 1 | ||
reason: InstallSucceeded | ||
status: "True" | ||
type: Released |
54 changes: 54 additions & 0 deletions
54
resource_customizations/helm.toolkit.fluxcd.io/HelmRelease/testdata/progressing.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
apiVersion: helm.toolkit.fluxcd.io/v2 | ||
kind: HelmRelease | ||
metadata: | ||
name: podinfo | ||
namespace: default | ||
spec: | ||
interval: 10m | ||
timeout: 5m | ||
chart: | ||
spec: | ||
chart: podinfo | ||
version: '6.5.*' | ||
sourceRef: | ||
kind: HelmRepository | ||
name: podinfo | ||
interval: 5m | ||
releaseName: podinfo | ||
install: | ||
remediation: | ||
retries: 3 | ||
upgrade: | ||
remediation: | ||
retries: 3 | ||
test: | ||
enable: true | ||
driftDetection: | ||
mode: enabled | ||
ignore: | ||
- paths: ["/spec/replicas"] | ||
target: | ||
kind: Deployment | ||
values: | ||
replicaCount: 2 | ||
status: | ||
conditions: | ||
- lastTransitionTime: "2024-07-16T12:00:00Z" | ||
message: Running 'upgrade' action with timeout of 5m0s | ||
observedGeneration: 3 | ||
reason: Progressing | ||
status: "True" | ||
type: Reconciling | ||
- lastTransitionTime: "2024-07-16T12:00:00Z" | ||
message: Running 'upgrade' action with timeout of 5m0s | ||
observedGeneration: 3 | ||
reason: Progressing | ||
status: Unknown | ||
type: Ready | ||
- lastTransitionTime: "2024-07-16T12:00:00Z" | ||
message: Helm install succeeded for release default/podinfo.v1 with | ||
chart podinfo@6.5.4 | ||
observedGeneration: 1 | ||
reason: InstallSucceeded | ||
status: "True" | ||
type: Released |
38 changes: 38 additions & 0 deletions
38
resource_customizations/image.toolkit.fluxcd.io/ImagePolicy/health.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
local hs = {} | ||
if obj.status ~= nil then | ||
if obj.status.conditions ~= nil then | ||
local numProgressing = 0 | ||
local numSucceeded = 0 | ||
local message = "" | ||
for _, condition in ipairs(obj.status.conditions) do | ||
if condition.type == "Ready" then | ||
if condition.status == "True" then | ||
numSucceeded = numSucceeded + 1 | ||
elseif condition.status == "False" then | ||
numProgressing = numProgressing + 1 | ||
end | ||
message = condition.reason | ||
elseif condition.type == "Reconciling" and condition.status == "True" then | ||
if condition.reason == "NewGeneration" or condition.reason == "AccessingRepository" or condition.reason == "ApplyingPolicy" then | ||
numProgressing = numProgressing + 1 | ||
end | ||
end | ||
end | ||
if(numProgressing == 2) then | ||
hs.message = message | ||
hs.status = "Progressing" | ||
return hs | ||
elseif(numSucceeded == 1) then | ||
hs.message = message | ||
hs.status = "Healthy" | ||
return hs | ||
else | ||
hs.message = message | ||
hs.status = "Degraded" | ||
return hs | ||
end | ||
end | ||
end | ||
hs.message = "Status unknown" | ||
hs.status = "Progressing" | ||
return hs |
13 changes: 13 additions & 0 deletions
13
resource_customizations/image.toolkit.fluxcd.io/ImagePolicy/health_test.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
tests: | ||
# - healthStatus: | ||
# status: Progressing | ||
# message: DependencyNotReady | ||
# inputPath: testdata/progressing.yaml | ||
- healthStatus: | ||
status: Degraded | ||
message: DependencyNotReady | ||
inputPath: testdata/degraded.yaml | ||
- healthStatus: | ||
status: Healthy | ||
message: Succeeded | ||
inputPath: testdata/healthy.yaml |
26 changes: 26 additions & 0 deletions
26
resource_customizations/image.toolkit.fluxcd.io/ImagePolicy/testdata/degraded.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
apiVersion: image.toolkit.fluxcd.io/v1beta2 | ||
kind: ImagePolicy | ||
metadata: | ||
name: podinfo | ||
namespace: argocd | ||
spec: | ||
imageRepositoryRef: | ||
name: podinfo-faulty | ||
policy: | ||
semver: | ||
range: x.x.x | ||
status: | ||
conditions: | ||
- lastTransitionTime: "2024-07-16T12:00:00Z" | ||
message: 'processing object: new generation 1 -> 2' | ||
observedGeneration: 2 | ||
reason: ProgressingWithRetry | ||
status: "True" | ||
type: Reconciling | ||
- lastTransitionTime: "2024-07-16T12:00:00Z" | ||
message: 'failed to get the referred ImageRepository: referenced ImageRepository | ||
does not exist: ImageRepository.image.toolkit.fluxcd.io "podinfo-faulty" not found' | ||
observedGeneration: 2 | ||
reason: DependencyNotReady | ||
status: "False" | ||
type: Ready |
19 changes: 19 additions & 0 deletions
19
resource_customizations/image.toolkit.fluxcd.io/ImagePolicy/testdata/healthy.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
apiVersion: image.toolkit.fluxcd.io/v1beta2 | ||
kind: ImagePolicy | ||
metadata: | ||
name: podinfo | ||
namespace: argocd | ||
spec: | ||
imageRepositoryRef: | ||
name: podinfo | ||
policy: | ||
semver: | ||
range: x.x.x | ||
status: | ||
conditions: | ||
- lastTransitionTime: "2024-07-16T12:00:00Z" | ||
message: Latest image tag for 'stefanprodan/podinfo' resolved to 5.1.4 | ||
observedGeneration: 1 | ||
reason: Succeeded | ||
status: "True" | ||
type: Ready |
13 changes: 13 additions & 0 deletions
13
resource_customizations/image.toolkit.fluxcd.io/ImagePolicy/testdata/progressing.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apiVersion: image.toolkit.fluxcd.io/v1beta2 | ||
kind: ImagePolicy | ||
metadata: | ||
name: podinfo | ||
namespace: argocd | ||
spec: | ||
imageRepositoryRef: | ||
name: podinfo | ||
policy: | ||
semver: | ||
range: x.x.x | ||
status: | ||
conditions: [] |
Oops, something went wrong.