add customizations for helm.toolkit.fluxcd.io/v2beta1/HelmRelease
Signed-off-by: yike21 <yike21@qq.com>
This commit is contained in:
parent
b841c5493d
commit
2f421eaa4e
|
@ -0,0 +1,167 @@
|
||||||
|
apiVersion: config.karmada.io/v1alpha1
|
||||||
|
kind: ResourceInterpreterCustomization
|
||||||
|
metadata:
|
||||||
|
name: declarative-configuration-helmrelease
|
||||||
|
spec:
|
||||||
|
target:
|
||||||
|
apiVersion: helm.toolkit.fluxcd.io/v2beta1
|
||||||
|
kind: HelmRelease
|
||||||
|
customizations:
|
||||||
|
healthInterpretation:
|
||||||
|
luaScript: >
|
||||||
|
function InterpretHealth(observedObj)
|
||||||
|
if observedObj.status ~= nil and observedObj.status.conditions ~= nil then
|
||||||
|
for conditionIndex = 1, #observedObj.status.conditions do
|
||||||
|
if observedObj.status.conditions[conditionIndex].type == 'Ready' and observedObj.status.conditions[conditionIndex].status == 'True' and observedObj.status.conditions[conditionIndex].reason == 'ReconciliationSucceeded' then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
statusAggregation:
|
||||||
|
luaScript: >
|
||||||
|
function AggregateStatus(desiredObj, statusItems)
|
||||||
|
if statusItems == nil then
|
||||||
|
return desiredObj
|
||||||
|
end
|
||||||
|
desiredObj.status = {}
|
||||||
|
desiredObj.status.conditions = {}
|
||||||
|
conditions = {}
|
||||||
|
local conditionsIndex = 1
|
||||||
|
for i = 1, #statusItems do
|
||||||
|
if statusItems[i].status ~= nil and statusItems[i].status.lastAttemptedRevision ~= nil and statusItems[i].status.lastAttemptedRevision ~= '' then
|
||||||
|
desiredObj.status.lastAttemptedRevision = statusItems[i].status.lastAttemptedRevision
|
||||||
|
end
|
||||||
|
if statusItems[i].status ~= nil and statusItems[i].status.lastAppliedRevision ~= nil and statusItems[i].status.lastAppliedRevision ~= '' then
|
||||||
|
desiredObj.status.lastAppliedRevision = statusItems[i].status.lastAppliedRevision
|
||||||
|
end
|
||||||
|
if statusItems[i].status ~= nil and statusItems[i].status.lastHandledReconcileAt ~= nil and statusItems[i].status.lastHandledReconcileAt ~= '' then
|
||||||
|
desiredObj.status.lastHandledReconcileAt = statusItems[i].status.lastHandledReconcileAt
|
||||||
|
end
|
||||||
|
if statusItems[i].status ~= nil and statusItems[i].status.lastAttemptedValuesChecksum ~= nil and statusItems[i].status.lastAttemptedValuesChecksum ~= '' then
|
||||||
|
desiredObj.status.lastAttemptedValuesChecksum = statusItems[i].status.lastAttemptedValuesChecksum
|
||||||
|
end
|
||||||
|
if statusItems[i].status ~= nil and statusItems[i].status.helmChart ~= nil and statusItems[i].status.helmChart ~= '' then
|
||||||
|
desiredObj.status.helmChart = statusItems[i].status.helmChart
|
||||||
|
end
|
||||||
|
if statusItems[i].status ~= nil and statusItems[i].status.lastReleaseRevision ~= nil then
|
||||||
|
desiredObj.status.lastReleaseRevision = statusItems[i].status.lastReleaseRevision
|
||||||
|
end
|
||||||
|
if statusItems[i].status ~= nil and statusItems[i].status.failures ~= nil then
|
||||||
|
if desiredObj.status.failures ~= nil then
|
||||||
|
desiredObj.status.failures = desiredObj.status.failures + statusItems[i].status.failures
|
||||||
|
else
|
||||||
|
desiredObj.status.failures = statusItems[i].status.failures
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if statusItems[i].status ~= nil and statusItems[i].status.upgradeFailures ~= nil then
|
||||||
|
if desiredObj.status.upgradeFailures ~= nil then
|
||||||
|
desiredObj.status.upgradeFailures = desiredObj.status.upgradeFailures + statusItems[i].status.upgradeFailures
|
||||||
|
else
|
||||||
|
desiredObj.status.upgradeFailures = statusItems[i].status.upgradeFailures
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if statusItems[i].status ~= nil and statusItems[i].status.installFailures ~= nil then
|
||||||
|
if desiredObj.status.installFailures ~= nil then
|
||||||
|
desiredObj.status.installFailures = desiredObj.status.installFailures + statusItems[i].status.installFailures
|
||||||
|
else
|
||||||
|
desiredObj.status.installFailures = statusItems[i].status.installFailures
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if statusItems[i].status ~= nil and statusItems[i].status.conditions ~= nil then
|
||||||
|
for conditionIndex = 1, #statusItems[i].status.conditions do
|
||||||
|
statusItems[i].status.conditions[conditionIndex].message = statusItems[i].clusterName..'='..statusItems[i].status.conditions[conditionIndex].message
|
||||||
|
hasCondition = false
|
||||||
|
for index = 1, #conditions do
|
||||||
|
if conditions[index].type == statusItems[i].status.conditions[conditionIndex].type and conditions[index].status == statusItems[i].status.conditions[conditionIndex].status and conditions[index].reason == statusItems[i].status.conditions[conditionIndex].reason then
|
||||||
|
conditions[index].message = conditions[index].message..', '..statusItems[i].status.conditions[conditionIndex].message
|
||||||
|
hasCondition = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not hasCondition then
|
||||||
|
conditions[conditionsIndex] = statusItems[i].status.conditions[conditionIndex]
|
||||||
|
conditionsIndex = conditionsIndex + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
desiredObj.status.observedGeneration = desiredObj.metadata.generation
|
||||||
|
desiredObj.status.conditions = conditions
|
||||||
|
return desiredObj
|
||||||
|
end
|
||||||
|
retention:
|
||||||
|
luaScript: >
|
||||||
|
function Retain(desiredObj, observedObj)
|
||||||
|
if observedObj.spec.suspend ~= nil then
|
||||||
|
desiredObj.spec.suspend = observedObj.spec.suspend
|
||||||
|
end
|
||||||
|
return desiredObj
|
||||||
|
end
|
||||||
|
statusReflection:
|
||||||
|
luaScript: >
|
||||||
|
function ReflectStatus (observedObj)
|
||||||
|
status = {}
|
||||||
|
if observedObj == nil or observedObj.status == nil then
|
||||||
|
return status
|
||||||
|
end
|
||||||
|
return observedObj.status
|
||||||
|
end
|
||||||
|
dependencyInterpretation:
|
||||||
|
luaScript: >
|
||||||
|
function GetDependencies(desiredObj)
|
||||||
|
dependentSecrets = {}
|
||||||
|
dependentSas = {}
|
||||||
|
dependentCms = {}
|
||||||
|
refs = {}
|
||||||
|
local idx = 1
|
||||||
|
if desiredObj.spec.valuesFrom ~= nil then
|
||||||
|
valuesFrom = desiredObj.spec.valuesFrom
|
||||||
|
for valuesIndex = 1, #valuesFrom do
|
||||||
|
if valuesFrom[valuesIndex].kind == 'Secret' then
|
||||||
|
dependentSecrets[valuesFrom[valuesIndex].name] = true
|
||||||
|
end
|
||||||
|
if valuesFrom[valuesIndex].kind == 'ConfigMap' then
|
||||||
|
dependentCms[valuesFrom[valuesIndex].name] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if desiredObj.spec.chart ~= nil and desiredObj.spec.chart.spec ~= nil and desiredObj.spec.chart.spec.verify ~= nil and desiredObj.spec.chart.spec.verify.secretRef ~= nil and desiredObj.spec.chart.spec.verify.secretRef.name ~= '' then
|
||||||
|
dependentSecrets[desiredObj.spec.chart.spec.verify.secretRef.name] = true
|
||||||
|
end
|
||||||
|
if desiredObj.spec.kubeConfig ~= nil and desiredObj.spec.kubeConfig.secretRef ~= nil and desiredObj.spec.kubeConfig.secretRef.name ~= '' then
|
||||||
|
dependentSecrets[desiredObj.spec.kubeConfig.secretRef.name] = true
|
||||||
|
end
|
||||||
|
if desiredObj.spec.serviceAccountName ~= nil and desiredObj.spec.serviceAccountName ~= '' then
|
||||||
|
dependentSas[desiredObj.spec.serviceAccountName] = true
|
||||||
|
end
|
||||||
|
for key, value in pairs(dependentSecrets) do
|
||||||
|
dependObj = {}
|
||||||
|
dependObj.apiVersion = 'v1'
|
||||||
|
dependObj.kind = 'Secret'
|
||||||
|
dependObj.name = key
|
||||||
|
dependObj.namespace = desiredObj.metadata.namespace
|
||||||
|
refs[idx] = dependObj
|
||||||
|
idx = idx + 1
|
||||||
|
end
|
||||||
|
for key, value in pairs(dependentSas) do
|
||||||
|
dependObj = {}
|
||||||
|
dependObj.apiVersion = 'v1'
|
||||||
|
dependObj.kind = 'ServiceAccount'
|
||||||
|
dependObj.name = key
|
||||||
|
dependObj.namespace = desiredObj.metadata.namespace
|
||||||
|
refs[idx] = dependObj
|
||||||
|
idx = idx + 1
|
||||||
|
end
|
||||||
|
for key, value in pairs(dependentCms) do
|
||||||
|
dependObj = {}
|
||||||
|
dependObj.apiVersion = 'v1'
|
||||||
|
dependObj.kind = 'ConfigMap'
|
||||||
|
dependObj.name = key
|
||||||
|
dependObj.namespace = desiredObj.metadata.namespace
|
||||||
|
refs[idx] = dependObj
|
||||||
|
idx = idx + 1
|
||||||
|
end
|
||||||
|
return refs
|
||||||
|
end
|
|
@ -0,0 +1,19 @@
|
||||||
|
apiVersion: helm.toolkit.fluxcd.io/v2beta1
|
||||||
|
kind: HelmRelease
|
||||||
|
metadata:
|
||||||
|
name: sample
|
||||||
|
namespace: default
|
||||||
|
spec:
|
||||||
|
interval: 5m
|
||||||
|
chart:
|
||||||
|
spec:
|
||||||
|
chart: "./charts/podinfo"
|
||||||
|
version: ">=4.0.0 <5.0.0"
|
||||||
|
sourceRef:
|
||||||
|
kind: GitRepository
|
||||||
|
name: podinfo
|
||||||
|
namespace: default
|
||||||
|
interval: 1m
|
||||||
|
test:
|
||||||
|
enable: true
|
||||||
|
ignoreFailures: true
|
|
@ -0,0 +1,48 @@
|
||||||
|
apiVersion: helm.toolkit.fluxcd.io/v2beta1
|
||||||
|
kind: HelmRelease
|
||||||
|
metadata:
|
||||||
|
name: sample
|
||||||
|
namespace: default
|
||||||
|
spec:
|
||||||
|
interval: 5m
|
||||||
|
chart:
|
||||||
|
spec:
|
||||||
|
chart: "./charts/podinfo"
|
||||||
|
version: ">=4.0.0 <5.0.0"
|
||||||
|
sourceRef:
|
||||||
|
kind: GitRepository
|
||||||
|
name: podinfo
|
||||||
|
namespace: default
|
||||||
|
interval: 1m
|
||||||
|
verify:
|
||||||
|
secretRef:
|
||||||
|
name: fake-verify-secret
|
||||||
|
test:
|
||||||
|
enable: true
|
||||||
|
ignoreFailures: true
|
||||||
|
serviceAccountName: fake-sa
|
||||||
|
kubeConfig:
|
||||||
|
secretRef:
|
||||||
|
name:
|
||||||
|
fake-secret
|
||||||
|
valuesFrom:
|
||||||
|
- kind: ConfigMap
|
||||||
|
name: fake-configmap
|
||||||
|
status:
|
||||||
|
conditions:
|
||||||
|
- lastTransitionTime: "2023-05-01T07:11:16Z"
|
||||||
|
message: Release reconciliation succeeded
|
||||||
|
reason: ReconciliationSucceeded
|
||||||
|
status: "True"
|
||||||
|
type: Ready
|
||||||
|
- lastTransitionTime: "2023-05-01T07:11:16Z"
|
||||||
|
message: Helm install succeeded
|
||||||
|
reason: InstallSucceeded
|
||||||
|
status: "True"
|
||||||
|
type: Released
|
||||||
|
helmChart: test-helmrelease/test-helmrelease-sample
|
||||||
|
lastAppliedRevision: 6.3.5
|
||||||
|
lastAttemptedRevision: 6.3.5
|
||||||
|
lastAttemptedValuesChecksum: da39a3ee5e6b4b0d3255bfef95601890afd80709
|
||||||
|
lastReleaseRevision: 1
|
||||||
|
observedGeneration: 1
|
|
@ -0,0 +1,43 @@
|
||||||
|
applied: true
|
||||||
|
clusterName: member1
|
||||||
|
health: Healthy
|
||||||
|
status:
|
||||||
|
conditions:
|
||||||
|
- lastTransitionTime: "2023-05-01T07:11:16Z"
|
||||||
|
message: Release reconciliation succeeded
|
||||||
|
reason: ReconciliationSucceeded
|
||||||
|
status: "True"
|
||||||
|
type: Ready
|
||||||
|
- lastTransitionTime: "2023-05-01T07:11:16Z"
|
||||||
|
message: Helm install succeeded
|
||||||
|
reason: InstallSucceeded
|
||||||
|
status: "True"
|
||||||
|
type: Released
|
||||||
|
helmChart: test-helmrelease/test-helmrelease-sample
|
||||||
|
lastAppliedRevision: 6.3.5
|
||||||
|
lastAttemptedRevision: 6.3.5
|
||||||
|
lastAttemptedValuesChecksum: da39a3ee5e6b4b0d3255bfef95601890afd80709
|
||||||
|
lastReleaseRevision: 1
|
||||||
|
observedGeneration: 1
|
||||||
|
---
|
||||||
|
applied: true
|
||||||
|
clusterName: member3
|
||||||
|
health: Healthy
|
||||||
|
status:
|
||||||
|
conditions:
|
||||||
|
- lastTransitionTime: "2023-05-01T07:11:17Z"
|
||||||
|
message: Release reconciliation succeeded
|
||||||
|
reason: ReconciliationSucceeded
|
||||||
|
status: "True"
|
||||||
|
type: Ready
|
||||||
|
- lastTransitionTime: "2023-05-01T07:11:17Z"
|
||||||
|
message: Helm install succeeded
|
||||||
|
reason: InstallSucceeded
|
||||||
|
status: "True"
|
||||||
|
type: Released
|
||||||
|
helmChart: test-helmrelease/test-helmrelease-sample
|
||||||
|
lastAppliedRevision: 6.3.5
|
||||||
|
lastAttemptedRevision: 6.3.5
|
||||||
|
lastAttemptedValuesChecksum: da39a3ee5e6b4b0d3255bfef95601890afd80709
|
||||||
|
lastReleaseRevision: 1
|
||||||
|
observedGeneration: 1
|
Loading…
Reference in New Issue