add customizations for source.toolkit.fluxcd.io/v1/GitRepository

Signed-off-by: yike21 <yike21@qq.com>
This commit is contained in:
yike21 2023-04-27 19:54:20 +08:00
parent db01a125e2
commit a8f4aef875
4 changed files with 200 additions and 0 deletions

View File

@ -0,0 +1,105 @@
apiVersion: config.karmada.io/v1alpha1
kind: ResourceInterpreterCustomization
metadata:
name: declarative-configuration-gitrepository
spec:
target:
apiVersion: source.toolkit.fluxcd.io/v1
kind: GitRepository
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 == 'Succeeded' 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.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
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
status.conditions = observedObj.status.conditions
status.artifact = observedObj.status.artifact
status.observedIgnore = observedObj.status.observedIgnore
status.observedRecurseSubmodules = observedObj.status.observedRecurseSubmodules
status.lastHandledReconcileAt = observedObj.status.lastHandledReconcileAt
return status
end
dependencyInterpretation:
luaScript: >
function GetDependencies(desiredObj)
dependentSecrets = {}
refs = {}
local idx = 1
if desiredObj.spec.secretRef ~= nil and desiredObj.spec.secretRef.name ~= '' then
dependentSecrets[desiredObj.spec.secretRef.name] = true
end
if desiredObj.spec.verify ~= nil and desiredObj.spec.verify.secretRef ~= nil and desiredObj.spec.verify.secretRef.name ~= '' then
dependentSecrets[desiredObj.spec.verify.secretRef.name] = 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
return refs
end

View File

@ -0,0 +1,10 @@
apiVersion: source.toolkit.fluxcd.io/v1
kind: GitRepository
metadata:
name: sample
namespace: test-gitrepository
spec:
interval: 30s
ref:
branch: master
url: https://github.com/stefanprodan/podinfo

View File

@ -0,0 +1,36 @@
apiVersion: source.toolkit.fluxcd.io/v1
kind: GitRepository
metadata:
name: sample
namespace: test-gitrepository
spec:
interval: 30s
ref:
branch: master
secretRef:
name: fake-secret
timeout: 60s
url: https://github.com/stefanprodan/podinfo
suspend: true
status:
artifact:
digest: sha256:a375b2ca68275734e3850d3c80e0bc20c1d7a4daa1a9717056d5c0c563ea0719
lastUpdateTime: "2023-05-01T10:17:09Z"
path: gitrepository/test-gitrepository/sample/0647aea75b85755411b007a290b9321668370be5.tar.gz
revision: master@sha1:0647aea75b85755411b007a290b9321668370be5
size: 83516
url: http://source-controller.flux-system.svc.cluster.local./gitrepository/test-gitrepository/sample/0647aea75b85755411b007a290b9321668370be5.tar.gz
conditions:
- lastTransitionTime: "2023-05-01T10:17:09Z"
message: stored artifact for revision 'master@sha1:0647aea75b85755411b007a290b9321668370be5'
observedGeneration: 1
reason: Succeeded
status: "True"
type: Ready
- lastTransitionTime: "2023-05-01T10:17:09Z"
message: stored artifact for revision 'master@sha1:0647aea75b85755411b007a290b9321668370be5'
observedGeneration: 1
reason: Succeeded
status: "True"
type: ArtifactInStorage
observedGeneration: 1

View File

@ -0,0 +1,49 @@
applied: true
clusterName: member1
health: Healthy
status:
artifact:
digest: sha256:a375b2ca68275734e3850d3c80e0bc20c1d7a4daa1a9717056d5c0c563ea0719
lastUpdateTime: "2023-05-01T10:17:09Z"
path: gitrepository/test-gitrepository/sample/0647aea75b85755411b007a290b9321668370be5.tar.gz
revision: master@sha1:0647aea75b85755411b007a290b9321668370be5
size: 83516
url: http://source-controller.flux-system.svc.cluster.local./gitrepository/test-gitrepository/sample/0647aea75b85755411b007a290b9321668370be5.tar.gz
conditions:
- lastTransitionTime: "2023-05-01T10:17:09Z"
message: stored artifact for revision 'master@sha1:0647aea75b85755411b007a290b9321668370be5'
observedGeneration: 1
reason: Succeeded
status: "True"
type: Ready
- lastTransitionTime: "2023-05-01T10:17:09Z"
message: stored artifact for revision 'master@sha1:0647aea75b85755411b007a290b9321668370be5'
observedGeneration: 1
reason: Succeeded
status: "True"
type: ArtifactInStorage
---
applied: true
clusterName: member3
health: Healthy
status:
artifact:
digest: sha256:a375b2ca68275734e3850d3c80e0bc20c1d7a4daa1a9717056d5c0c563ea0719
lastUpdateTime: "2023-05-01T10:17:08Z"
path: gitrepository/test-gitrepository/sample/0647aea75b85755411b007a290b9321668370be5.tar.gz
revision: master@sha1:0647aea75b85755411b007a290b9321668370be5
size: 83516
url: http://source-controller.flux-system.svc.cluster.local./gitrepository/test-gitrepository/sample/0647aea75b85755411b007a290b9321668370be5.tar.gz
conditions:
- lastTransitionTime: "2023-05-01T10:17:08Z"
message: stored artifact for revision 'master@sha1:0647aea75b85755411b007a290b9321668370be5'
observedGeneration: 1
reason: Succeeded
status: "True"
type: Ready
- lastTransitionTime: "2023-05-01T10:17:08Z"
message: stored artifact for revision 'master@sha1:0647aea75b85755411b007a290b9321668370be5'
observedGeneration: 1
reason: Succeeded
status: "True"
type: ArtifactInStorage