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

Align federated helmrepositories.source.toolkit.fluxcd.io observedGeneration semantics with its native #5196

Merged
merged 1 commit into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,42 @@ spec:
statusAggregation:
luaScript: >
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 HelmRepository is not spread to any cluster, its status also should be aggregated
if statusItems == nil then
desiredObj.status.observedGeneration = desiredObj.metadata.generation
desiredObj.status.artifact = {}
desiredObj.status.conditions = {}
desiredObj.status.url = ''
return desiredObj
end
desiredObj.status = {}
desiredObj.status.conditions = {}
conditions = {}

local artifact = {}
local conditions = {}
local generation = desiredObj.metadata.generation
local observedGeneration = desiredObj.status.observedGeneration
local url = ''

-- Count all members that their status is updated to the latest generation
local observedResourceTemplateGenerationCount = 0

local conditionsIndex = 1
for i = 1, #statusItems do
if statusItems[i].status ~= nil and statusItems[i].status.artifact ~= nil then
desiredObj.status.artifact = statusItems[i].status.artifact
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
Comment on lines -36 to -37
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two lines are the extra settings from before, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I find that this field is not in the current helmrepositories.source.toolkit.fluxcd.io API.
It appears to be a past bug that wasn't triggered yet.

artifact = statusItems[i].status.artifact
end
if statusItems[i].status ~= nil and statusItems[i].status.url ~= nil and statusItems[i].status.url ~= '' then
desiredObj.status.url = statusItems[i].status.url
url = statusItems[i].status.url
end
if statusItems[i].status ~= nil and statusItems[i].status.conditions ~= nil then
for conditionIndex = 1, #statusItems[i].status.conditions do
Expand All @@ -56,9 +76,35 @@ spec:
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
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.artifact = artifact
desiredObj.status.conditions = conditions
desiredObj.status.url = url
return desiredObj
end
retention:
Expand All @@ -72,14 +118,29 @@ spec:
statusReflection:
luaScript: >
function ReflectStatus (observedObj)
status = {}
if observedObj == nil or observedObj.status == nil then
local status = {}
if observedObj == nil or observedObj.status == nil then
return status
end
status.conditions = observedObj.status.conditions
status.artifact = observedObj.status.artifact
status.conditions = observedObj.status.conditions
status.observedGeneration = observedObj.status.observedGeneration
status.url = observedObj.status.url
status.lastHandledReconcileAt = observedObj.status.lastHandledReconcileAt

-- 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
dependencyInterpretation:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ kind: HelmRepository
metadata:
name: podinfo
namespace: test-helmrepository
generation: 1
spec:
interval: 5m0s
url: https://stefanprodan.github.io/podinfo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: HelmRepository
metadata:
annotations:
resourcetemplate.karmada.io/generation: "1"
name: podinfo
namespace: test-helmrepository
generation: 1
spec:
interval: 5m0s
provider: generic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ status:
reason: Succeeded
status: "True"
type: ArtifactInStorage
generation: 1
observedGeneration: 1
resourceTemplateGeneration: 1
url: http://source-controller.flux-system.svc.cluster.local./helmrepository/test-helmrepository/sample/index.yaml
---
applied: true
Expand All @@ -48,4 +51,7 @@ status:
reason: Succeeded
status: "True"
type: ArtifactInStorage
generation: 1
observedGeneration: 1
resourceTemplateGeneration: 1
url: http://source-controller.flux-system.svc.cluster.local./helmrepository/test-helmrepository/sample/index.yaml