Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add custom resource health for flux resources #19082

Merged
merged 3 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 16 additions & 0 deletions docs/operator-manual/upgrading/2.12-2.13.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,19 @@ The following actions are now available:
| OCIRepository | `Suspend`, `Resume`, `Reconcile` |

If you want to use these actions do not forget to update the permissions (RBAC) for your Argo CD instance.

## Custom Resource Health for Flux Resources

[`Custom Resource Health`](../health.md#custom-health-checks) has been added for Flux Resources.
The following Flux resources now support health checks:
- HelmRelease
- ImagePolicy
- ImageRepository
- ImageUpdateAutomation
- Kustomization
- Receiver
- Bucket
- GitRepository
- HelmChart
- HelmRepository
- OCIRepository
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
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
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
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
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
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
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
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
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
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: []
Loading