Merge pull request #5311 from yike21/generation-helmrelease
Align federated helmreleases.helm.toolkit.fluxcd.io observedGeneration semantics with its native
This commit is contained in:
commit
37dfa37515
|
@ -22,51 +22,76 @@ spec:
|
||||||
statusAggregation:
|
statusAggregation:
|
||||||
luaScript: >
|
luaScript: >
|
||||||
function AggregateStatus(desiredObj, statusItems)
|
function AggregateStatus(desiredObj, statusItems)
|
||||||
|
if desiredObj.status == nil then
|
||||||
|
desiredObj.status = {}
|
||||||
|
end
|
||||||
|
if desiredObj.metadata.generation == nil then
|
||||||
|
desiredObj.metadata.generation = 0
|
||||||
|
end
|
||||||
|
if desiredObj.status.observedGeneration == nil then
|
||||||
|
desiredObj.status.observedGeneration = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Initialize status fields if status doest not exist
|
||||||
|
-- If the Kustomization is not spread to any cluster, its status also should be aggregated
|
||||||
if statusItems == nil then
|
if statusItems == nil then
|
||||||
|
desiredObj.status.observedGeneration = desiredObj.metadata.generation
|
||||||
|
desiredObj.status.lastAttemptedRevision = ''
|
||||||
|
desiredObj.status.lastAppliedRevision = ''
|
||||||
|
desiredObj.status.lastAttemptedValuesChecksum = ''
|
||||||
|
desiredObj.status.helmChart = ''
|
||||||
|
desiredObj.status.lastReleaseRevision = ''
|
||||||
|
desiredObj.status.failures = 0
|
||||||
|
desiredObj.status.upgradeFailures = 0
|
||||||
|
desiredObj.status.installFailures = 0
|
||||||
|
desiredObj.status.conditions = {}
|
||||||
return desiredObj
|
return desiredObj
|
||||||
end
|
end
|
||||||
desiredObj.status = {}
|
|
||||||
desiredObj.status.conditions = {}
|
local conditions = {}
|
||||||
conditions = {}
|
local generation = desiredObj.metadata.generation
|
||||||
|
local lastAttemptedRevision = desiredObj.status.lastAttemptedRevision
|
||||||
|
local lastAppliedRevision = desiredObj.status.lastAppliedRevision
|
||||||
|
local lastAttemptedValuesChecksum = desiredObj.status.lastAttemptedValuesChecksum
|
||||||
|
local helmChart = desiredObj.status.helmChart
|
||||||
|
local lastReleaseRevision = desiredObj.status.lastReleaseRevision
|
||||||
|
local failures = desiredObj.status.failures
|
||||||
|
local upgradeFailures = desiredObj.status.upgradeFailures
|
||||||
|
local installFailures = desiredObj.status.installFailures
|
||||||
|
|
||||||
|
-- Count all members that their status is updated to the latest generation
|
||||||
|
local observedResourceTemplateGenerationCount = 0
|
||||||
|
|
||||||
local conditionsIndex = 1
|
local conditionsIndex = 1
|
||||||
for i = 1, #statusItems do
|
for i = 1, #statusItems do
|
||||||
if statusItems[i].status ~= nil and statusItems[i].status.lastAttemptedRevision ~= nil and statusItems[i].status.lastAttemptedRevision ~= '' then
|
if statusItems[i].status ~= nil and statusItems[i].status.lastAttemptedRevision ~= nil and statusItems[i].status.lastAttemptedRevision ~= '' then
|
||||||
desiredObj.status.lastAttemptedRevision = statusItems[i].status.lastAttemptedRevision
|
lastAttemptedRevision = statusItems[i].status.lastAttemptedRevision
|
||||||
end
|
end
|
||||||
if statusItems[i].status ~= nil and statusItems[i].status.lastAppliedRevision ~= nil and statusItems[i].status.lastAppliedRevision ~= '' then
|
if statusItems[i].status ~= nil and statusItems[i].status.lastAppliedRevision ~= nil and statusItems[i].status.lastAppliedRevision ~= '' then
|
||||||
desiredObj.status.lastAppliedRevision = statusItems[i].status.lastAppliedRevision
|
lastAppliedRevision = statusItems[i].status.lastAppliedRevision
|
||||||
end
|
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
|
if statusItems[i].status ~= nil and statusItems[i].status.lastAttemptedValuesChecksum ~= nil and statusItems[i].status.lastAttemptedValuesChecksum ~= '' then
|
||||||
desiredObj.status.lastAttemptedValuesChecksum = statusItems[i].status.lastAttemptedValuesChecksum
|
lastAttemptedValuesChecksum = statusItems[i].status.lastAttemptedValuesChecksum
|
||||||
end
|
end
|
||||||
if statusItems[i].status ~= nil and statusItems[i].status.helmChart ~= nil and statusItems[i].status.helmChart ~= '' then
|
if statusItems[i].status ~= nil and statusItems[i].status.helmChart ~= nil and statusItems[i].status.helmChart ~= '' then
|
||||||
desiredObj.status.helmChart = statusItems[i].status.helmChart
|
helmChart = statusItems[i].status.helmChart
|
||||||
end
|
end
|
||||||
if statusItems[i].status ~= nil and statusItems[i].status.lastReleaseRevision ~= nil then
|
if statusItems[i].status ~= nil and statusItems[i].status.lastReleaseRevision ~= nil then
|
||||||
desiredObj.status.lastReleaseRevision = statusItems[i].status.lastReleaseRevision
|
lastReleaseRevision = statusItems[i].status.lastReleaseRevision
|
||||||
end
|
end
|
||||||
if statusItems[i].status ~= nil and statusItems[i].status.failures ~= nil then
|
if statusItems[i].status ~= nil and statusItems[i].status.failures ~= nil then
|
||||||
if desiredObj.status.failures ~= nil then
|
if desiredObj.status.failures ~= nil then
|
||||||
desiredObj.status.failures = desiredObj.status.failures + statusItems[i].status.failures
|
failures = failures + statusItems[i].status.failures
|
||||||
else
|
|
||||||
desiredObj.status.failures = statusItems[i].status.failures
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if statusItems[i].status ~= nil and statusItems[i].status.upgradeFailures ~= nil then
|
if statusItems[i].status ~= nil and statusItems[i].status.upgradeFailures ~= nil then
|
||||||
if desiredObj.status.upgradeFailures ~= nil then
|
if desiredObj.status.upgradeFailures ~= nil then
|
||||||
desiredObj.status.upgradeFailures = desiredObj.status.upgradeFailures + statusItems[i].status.upgradeFailures
|
upgradeFailures = upgradeFailures + statusItems[i].status.upgradeFailures
|
||||||
else
|
|
||||||
desiredObj.status.upgradeFailures = statusItems[i].status.upgradeFailures
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if statusItems[i].status ~= nil and statusItems[i].status.installFailures ~= nil then
|
if statusItems[i].status ~= nil and statusItems[i].status.installFailures ~= nil then
|
||||||
if desiredObj.status.installFailures ~= nil then
|
if desiredObj.status.installFailures ~= nil then
|
||||||
desiredObj.status.installFailures = desiredObj.status.installFailures + statusItems[i].status.installFailures
|
installFailures = installFailures + statusItems[i].status.installFailures
|
||||||
else
|
|
||||||
desiredObj.status.installFailures = statusItems[i].status.installFailures
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if statusItems[i].status ~= nil and statusItems[i].status.conditions ~= nil then
|
if statusItems[i].status ~= nil and statusItems[i].status.conditions ~= nil then
|
||||||
|
@ -86,9 +111,41 @@ spec:
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Check if the member's status is updated to the latest generation
|
||||||
|
local resourceTemplateGeneration = 0
|
||||||
|
if statusItems[i].status ~= nil and statusItems[i].status.resourceTemplateGeneration ~= nil then
|
||||||
|
resourceTemplateGeneration = statusItems[i].status.resourceTemplateGeneration
|
||||||
|
end
|
||||||
|
local memberGeneration = 0
|
||||||
|
if statusItems[i].status ~= nil and statusItems[i].status.generation ~= nil then
|
||||||
|
memberGeneration = statusItems[i].status.generation
|
||||||
|
end
|
||||||
|
local memberObservedGeneration = 0
|
||||||
|
if statusItems[i].status ~= nil and statusItems[i].status.observedGeneration ~= nil then
|
||||||
|
memberObservedGeneration = statusItems[i].status.observedGeneration
|
||||||
|
end
|
||||||
|
if resourceTemplateGeneration == generation and memberGeneration == memberObservedGeneration then
|
||||||
|
observedResourceTemplateGenerationCount = observedResourceTemplateGenerationCount + 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
desiredObj.status.observedGeneration = desiredObj.metadata.generation
|
|
||||||
|
-- Update the observed generation based on the observedResourceTemplateGenerationCount
|
||||||
|
if observedResourceTemplateGenerationCount == #statusItems then
|
||||||
|
desiredObj.status.observedGeneration = generation
|
||||||
|
else
|
||||||
|
desiredObj.status.observedGeneration = observedGeneration
|
||||||
|
end
|
||||||
|
|
||||||
desiredObj.status.conditions = conditions
|
desiredObj.status.conditions = conditions
|
||||||
|
desiredObj.status.lastAttemptedRevision = lastAttemptedRevision
|
||||||
|
desiredObj.status.lastAppliedRevision = lastAppliedRevision
|
||||||
|
desiredObj.status.lastAttemptedValuesChecksum = lastAttemptedValuesChecksum
|
||||||
|
desiredObj.status.helmChart = helmChart
|
||||||
|
desiredObj.status.lastReleaseRevision = lastReleaseRevision
|
||||||
|
desiredObj.status.failures = failures
|
||||||
|
desiredObj.status.upgradeFailures = upgradeFailures
|
||||||
|
desiredObj.status.installFailures = installFailures
|
||||||
return desiredObj
|
return desiredObj
|
||||||
end
|
end
|
||||||
retention:
|
retention:
|
||||||
|
@ -102,11 +159,37 @@ spec:
|
||||||
statusReflection:
|
statusReflection:
|
||||||
luaScript: >
|
luaScript: >
|
||||||
function ReflectStatus (observedObj)
|
function ReflectStatus (observedObj)
|
||||||
status = {}
|
local status = {}
|
||||||
if observedObj == nil or observedObj.status == nil then
|
if observedObj == nil or observedObj.status == nil then
|
||||||
return status
|
return status
|
||||||
end
|
end
|
||||||
return observedObj.status
|
|
||||||
|
status.conditions = observedObj.status.conditions
|
||||||
|
status.observedGeneration = observedObj.status.observedGeneration
|
||||||
|
status.lastAttemptedRevision = observedObj.status.lastAttemptedRevision
|
||||||
|
status.lastAppliedRevision = observedObj.status.lastAppliedRevision
|
||||||
|
status.lastAttemptedValuesChecksum = observedObj.status.lastAttemptedValuesChecksum
|
||||||
|
status.helmChart = observedObj.status.helmChart
|
||||||
|
status.lastReleaseRevision = observedObj.status.lastReleaseRevision
|
||||||
|
status.failures = observedObj.status.failures
|
||||||
|
status.upgradeFailures = observedObj.status.upgradeFailures
|
||||||
|
status.installFailures = observedObj.status.installFailures
|
||||||
|
|
||||||
|
-- handle resource generation report
|
||||||
|
if observedObj.metadata == nil then
|
||||||
|
return status
|
||||||
|
end
|
||||||
|
status.generation = observedObj.metadata.generation
|
||||||
|
|
||||||
|
if observedObj.metadata.annotations == nil then
|
||||||
|
return status
|
||||||
|
end
|
||||||
|
local resourceTemplateGeneration = tonumber(observedObj.metadata.annotations["resourcetemplate.karmada.io/generation"])
|
||||||
|
if resourceTemplateGeneration ~= nil then
|
||||||
|
status.resourceTemplateGeneration = resourceTemplateGeneration
|
||||||
|
end
|
||||||
|
|
||||||
|
return status
|
||||||
end
|
end
|
||||||
dependencyInterpretation:
|
dependencyInterpretation:
|
||||||
luaScript: >
|
luaScript: >
|
||||||
|
|
|
@ -3,6 +3,7 @@ kind: HelmRelease
|
||||||
metadata:
|
metadata:
|
||||||
name: sample
|
name: sample
|
||||||
namespace: default
|
namespace: default
|
||||||
|
generation: 1
|
||||||
spec:
|
spec:
|
||||||
interval: 5m
|
interval: 5m
|
||||||
chart:
|
chart:
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
apiVersion: helm.toolkit.fluxcd.io/v2beta1
|
apiVersion: helm.toolkit.fluxcd.io/v2beta1
|
||||||
kind: HelmRelease
|
kind: HelmRelease
|
||||||
metadata:
|
metadata:
|
||||||
|
annotations:
|
||||||
|
resourcetemplate.karmada.io/generation: "1"
|
||||||
name: sample
|
name: sample
|
||||||
namespace: default
|
namespace: default
|
||||||
|
generation: 1
|
||||||
spec:
|
spec:
|
||||||
interval: 5m
|
interval: 5m
|
||||||
chart:
|
chart:
|
||||||
|
|
|
@ -13,12 +13,14 @@ status:
|
||||||
reason: InstallSucceeded
|
reason: InstallSucceeded
|
||||||
status: "True"
|
status: "True"
|
||||||
type: Released
|
type: Released
|
||||||
|
generation: 1
|
||||||
helmChart: test-helmrelease/test-helmrelease-sample
|
helmChart: test-helmrelease/test-helmrelease-sample
|
||||||
lastAppliedRevision: 6.3.5
|
lastAppliedRevision: 6.3.5
|
||||||
lastAttemptedRevision: 6.3.5
|
lastAttemptedRevision: 6.3.5
|
||||||
lastAttemptedValuesChecksum: da39a3ee5e6b4b0d3255bfef95601890afd80709
|
lastAttemptedValuesChecksum: da39a3ee5e6b4b0d3255bfef95601890afd80709
|
||||||
lastReleaseRevision: 1
|
lastReleaseRevision: 1
|
||||||
observedGeneration: 1
|
observedGeneration: 1
|
||||||
|
resourceTemplateGeneration: 1
|
||||||
---
|
---
|
||||||
applied: true
|
applied: true
|
||||||
clusterName: member3
|
clusterName: member3
|
||||||
|
@ -35,9 +37,11 @@ status:
|
||||||
reason: InstallSucceeded
|
reason: InstallSucceeded
|
||||||
status: "True"
|
status: "True"
|
||||||
type: Released
|
type: Released
|
||||||
|
generation: 1
|
||||||
helmChart: test-helmrelease/test-helmrelease-sample
|
helmChart: test-helmrelease/test-helmrelease-sample
|
||||||
lastAppliedRevision: 6.3.5
|
lastAppliedRevision: 6.3.5
|
||||||
lastAttemptedRevision: 6.3.5
|
lastAttemptedRevision: 6.3.5
|
||||||
lastAttemptedValuesChecksum: da39a3ee5e6b4b0d3255bfef95601890afd80709
|
lastAttemptedValuesChecksum: da39a3ee5e6b4b0d3255bfef95601890afd80709
|
||||||
lastReleaseRevision: 1
|
lastReleaseRevision: 1
|
||||||
observedGeneration: 1
|
observedGeneration: 1
|
||||||
|
resourceTemplateGeneration: 1
|
||||||
|
|
Loading…
Reference in New Issue