Align federated ocirepositories.source.toolkit.fluxcd.io observedGeneration semantics with its native
Signed-off-by: yike21 <yike21@qq.com>
This commit is contained in:
parent
d3adcf68ef
commit
00e83f7623
|
@ -22,22 +22,42 @@ 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 OCIRepository is not spread to any cluster, its status also should be aggregated
|
||||||
if statusItems == nil then
|
if statusItems == nil then
|
||||||
|
desiredObj.status.artifact = {}
|
||||||
|
desiredObj.status.conditions = {}
|
||||||
|
desiredObj.status.observedGeneration = desiredObj.metadata.generation
|
||||||
|
desiredObj.status.url = ''
|
||||||
return desiredObj
|
return desiredObj
|
||||||
end
|
end
|
||||||
desiredObj.status = {}
|
|
||||||
desiredObj.status.conditions = {}
|
local artifact = {}
|
||||||
conditions = {}
|
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
|
local conditionsIndex = 1
|
||||||
for i = 1, #statusItems do
|
for i = 1, #statusItems do
|
||||||
if statusItems[i].status ~= nil and statusItems[i].status.artifact ~= nil then
|
if statusItems[i].status ~= nil and statusItems[i].status.artifact ~= nil then
|
||||||
desiredObj.status.artifact = statusItems[i].status.artifact
|
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
|
|
||||||
end
|
end
|
||||||
if statusItems[i].status ~= nil and statusItems[i].status.url ~= nil and statusItems[i].status.url ~= '' then
|
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
|
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
|
||||||
for conditionIndex = 1, #statusItems[i].status.conditions do
|
for conditionIndex = 1, #statusItems[i].status.conditions do
|
||||||
|
@ -56,9 +76,34 @@ 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
|
end
|
||||||
desiredObj.status.observedGeneration = desiredObj.metadata.generation
|
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
|
||||||
|
|
||||||
|
-- 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.conditions = conditions
|
||||||
|
desiredObj.status.url = url
|
||||||
return desiredObj
|
return desiredObj
|
||||||
end
|
end
|
||||||
retention:
|
retention:
|
||||||
|
@ -72,16 +117,30 @@ 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
|
||||||
|
status.artifact = observedObj.status.artifact
|
||||||
status.conditions = observedObj.status.conditions
|
status.conditions = observedObj.status.conditions
|
||||||
status.url = observedObj.status.url
|
status.url = observedObj.status.url
|
||||||
status.artifact = observedObj.status.artifact
|
status.observedGeneration = observedObj.status.observedGeneration
|
||||||
status.observedIgnore = observedObj.status.observedIgnore
|
status.observedIgnore = observedObj.status.observedIgnore
|
||||||
status.observedLayerSelector = observedObj.status.observedLayerSelector
|
status.observedLayerSelector = observedObj.status.observedLayerSelector
|
||||||
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
|
return status
|
||||||
end
|
end
|
||||||
dependencyInterpretation:
|
dependencyInterpretation:
|
||||||
|
|
|
@ -3,6 +3,7 @@ kind: OCIRepository
|
||||||
metadata:
|
metadata:
|
||||||
name: sample
|
name: sample
|
||||||
namespace: test-ocirepository
|
namespace: test-ocirepository
|
||||||
|
generation: 1
|
||||||
spec:
|
spec:
|
||||||
interval: 5m
|
interval: 5m
|
||||||
ref:
|
ref:
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
apiVersion: source.toolkit.fluxcd.io/v1beta2
|
apiVersion: source.toolkit.fluxcd.io/v1beta2
|
||||||
kind: OCIRepository
|
kind: OCIRepository
|
||||||
metadata:
|
metadata:
|
||||||
|
annotations:
|
||||||
|
resourcetemplate.karmada.io/generation: "1"
|
||||||
name: sample
|
name: sample
|
||||||
namespace: test-ocirepository
|
namespace: test-ocirepository
|
||||||
|
generation: 1
|
||||||
spec:
|
spec:
|
||||||
interval: 5m
|
interval: 5m
|
||||||
provider: generic
|
provider: generic
|
||||||
|
|
|
@ -26,6 +26,9 @@ status:
|
||||||
reason: Succeeded
|
reason: Succeeded
|
||||||
status: "True"
|
status: "True"
|
||||||
type: ArtifactInStorage
|
type: ArtifactInStorage
|
||||||
|
generation: 1
|
||||||
|
observedGeneration: 1
|
||||||
|
resourceTemplateGeneration: 1
|
||||||
url: http://source-controller.flux-system.svc.cluster.local./ocirepository/test-ocirepository/sample/latest.tar.gz
|
url: http://source-controller.flux-system.svc.cluster.local./ocirepository/test-ocirepository/sample/latest.tar.gz
|
||||||
---
|
---
|
||||||
applied: true
|
applied: true
|
||||||
|
@ -56,4 +59,7 @@ status:
|
||||||
reason: Succeeded
|
reason: Succeeded
|
||||||
status: "True"
|
status: "True"
|
||||||
type: ArtifactInStorage
|
type: ArtifactInStorage
|
||||||
|
generation: 1
|
||||||
|
observedGeneration: 1
|
||||||
|
resourceTemplateGeneration: 1
|
||||||
url: http://source-controller.flux-system.svc.cluster.local./ocirepository/test-ocirepository/sample/latest.tar.gz
|
url: http://source-controller.flux-system.svc.cluster.local./ocirepository/test-ocirepository/sample/latest.tar.gz
|
||||||
|
|
Loading…
Reference in New Issue