Merge pull request #3482 from yike21/bundle-fluxcd-helmrepository

add customizations for source.toolkit.fluxcd.io/v1beta2/OCIRepository
This commit is contained in:
karmada-bot 2023-05-06 10:02:20 +08:00 committed by GitHub
commit 0e10088974
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 239 additions and 0 deletions

View File

@ -0,0 +1,125 @@
apiVersion: config.karmada.io/v1alpha1
kind: ResourceInterpreterCustomization
metadata:
name: declarative-configuration-ocirepository
spec:
target:
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: OCIRepository
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.url ~= nil and statusItems[i].status.url ~= '' then
desiredObj.status.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
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.url = observedObj.status.url
status.artifact = observedObj.status.artifact
status.observedIgnore = observedObj.status.observedIgnore
status.observedLayerSelector = observedObj.status.observedLayerSelector
status.lastHandledReconcileAt = observedObj.status.lastHandledReconcileAt
return status
end
dependencyInterpretation:
luaScript: >
function GetDependencies(desiredObj)
dependentSecrets = {}
dependentSas = {}
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
if desiredObj.spec.certSecretRef ~= nil and desiredObj.spec.certSecretRef.name ~= '' then
dependentSecrets[desiredObj.spec.certSecretRef.name] = true
end
if 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
return refs
end

View File

@ -0,0 +1,12 @@
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: OCIRepository
metadata:
name: sample
namespace: test-ocirepository
spec:
interval: 5m
ref:
branch: master
url: oci://ghcr.io/stefanprodan/podinfo-deploy
ref:
semver: "6.2.x"

View File

@ -0,0 +1,43 @@
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: OCIRepository
metadata:
name: sample
namespace: test-ocirepository
spec:
interval: 5m
provider: generic
ref:
semver: 6.2.x
secretRef:
name: fake-secret
serviceAccountName: fake-serviceaccount
timeout: 60s
url: oci://ghcr.io/stefanprodan/podinfo-deploy
suspend: true
status:
artifact:
digest: sha256:b6ccead26c790c8a0d40579905edc6d83f732ceacc0f4133f578fed456a2438a
lastUpdateTime: "2023-04-29T06:07:53Z"
metadata:
org.opencontainers.image.created: "2022-11-09T11:24:23Z"
org.opencontainers.image.revision: 6.2.3/8615cb75d926ea0ba5353b1d56867868c737bf5e
org.opencontainers.image.source: https://github.com/stefanprodan/podinfo
path: ocirepository/test-ocirepository/sample/sha256:a081a2c95eff48a80add59a9db3488c1653b8f82223ed409e32d925d228af792.tar.gz
revision: 6.2.3@sha256:a081a2c95eff48a80add59a9db3488c1653b8f82223ed409e32d925d228af792
size: 1103
url: http://source-controller.flux-system.svc.cluster.local./ocirepository/test-ocirepository/sample/sha256:a081a2c95eff48a80add59a9db3488c1653b8f82223ed409e32d925d228af792.tar.gz
conditions:
- lastTransitionTime: "2023-04-29T06:07:53Z"
message: stored artifact for digest '6.2.3@sha256:a081a2c95eff48a80add59a9db3488c1653b8f82223ed409e32d925d228af792'
observedGeneration: 1
reason: Succeeded
status: "True"
type: Ready
- lastTransitionTime: "2023-04-29T06:07:53Z"
message: stored artifact for digest '6.2.3@sha256:a081a2c95eff48a80add59a9db3488c1653b8f82223ed409e32d925d228af792'
observedGeneration: 1
reason: Succeeded
status: "True"
type: ArtifactInStorage
observedGeneration: 1
url: http://source-controller.flux-system.svc.cluster.local./ocirepository/test-ocirepository/sample/latest.tar.gz

View File

@ -0,0 +1,59 @@
applied: true
clusterName: member1
health: Healthy
status:
artifact:
digest: sha256:b6ccead26c790c8a0d40579905edc6d83f732ceacc0f4133f578fed456a2438a
lastUpdateTime: "2023-04-29T06:07:53Z"
metadata:
org.opencontainers.image.created: "2022-11-09T11:24:23Z"
org.opencontainers.image.revision: 6.2.3/8615cb75d926ea0ba5353b1d56867868c737bf5e
org.opencontainers.image.source: https://github.com/stefanprodan/podinfo
path: ocirepository/test-ocirepository/sample/sha256:a081a2c95eff48a80add59a9db3488c1653b8f82223ed409e32d925d228af792.tar.gz
revision: 6.2.3@sha256:a081a2c95eff48a80add59a9db3488c1653b8f82223ed409e32d925d228af792
size: 1103
url: http://source-controller.flux-system.svc.cluster.local./ocirepository/test-ocirepository/sample/sha256:a081a2c95eff48a80add59a9db3488c1653b8f82223ed409e32d925d228af792.tar.gz
conditions:
- lastTransitionTime: "2023-04-29T06:07:53Z"
message: stored artifact for digest '6.2.3@sha256:a081a2c95eff48a80add59a9db3488c1653b8f82223ed409e32d925d228af792'
observedGeneration: 1
reason: Succeeded
status: "True"
type: Ready
- lastTransitionTime: "2023-04-29T06:07:53Z"
message: stored artifact for digest '6.2.3@sha256:a081a2c95eff48a80add59a9db3488c1653b8f82223ed409e32d925d228af792'
observedGeneration: 1
reason: Succeeded
status: "True"
type: ArtifactInStorage
url: http://source-controller.flux-system.svc.cluster.local./ocirepository/test-ocirepository/sample/latest.tar.gz
---
applied: true
clusterName: member3
health: Healthy
status:
artifact:
digest: sha256:b6ccead26c790c8a0d40579905edc6d83f732ceacc0f4133f578fed456a2438a
lastUpdateTime: "2023-04-29T06:07:53Z"
metadata:
org.opencontainers.image.created: "2022-11-09T11:24:23Z"
org.opencontainers.image.revision: 6.2.3/8615cb75d926ea0ba5353b1d56867868c737bf5e
org.opencontainers.image.source: https://github.com/stefanprodan/podinfo
path: ocirepository/test-ocirepository/sample/sha256:a081a2c95eff48a80add59a9db3488c1653b8f82223ed409e32d925d228af792.tar.gz
revision: 6.2.3@sha256:a081a2c95eff48a80add59a9db3488c1653b8f82223ed409e32d925d228af792
size: 1103
url: http://source-controller.flux-system.svc.cluster.local./ocirepository/test-ocirepository/sample/sha256:a081a2c95eff48a80add59a9db3488c1653b8f82223ed409e32d925d228af792.tar.gz
conditions:
- lastTransitionTime: "2023-04-29T06:07:53Z"
message: stored artifact for digest '6.2.3@sha256:a081a2c95eff48a80add59a9db3488c1653b8f82223ed409e32d925d228af792'
observedGeneration: 1
reason: Succeeded
status: "True"
type: Ready
- lastTransitionTime: "2023-04-29T06:07:53Z"
message: stored artifact for digest '6.2.3@sha256:a081a2c95eff48a80add59a9db3488c1653b8f82223ed409e32d925d228af792'
observedGeneration: 1
reason: Succeeded
status: "True"
type: ArtifactInStorage
url: http://source-controller.flux-system.svc.cluster.local./ocirepository/test-ocirepository/sample/latest.tar.gz