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

add customizations for source.toolkit.fluxcd.io/v1beta2/HelmChart #3486

Merged
merged 1 commit into from
May 5, 2023
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
@@ -0,0 +1,114 @@
apiVersion: config.karmada.io/v1alpha1
kind: ResourceInterpreterCustomization
metadata:
name: declarative-configuration-helmchart
spec:
target:
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: HelmChart
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' then
if observedObj.status.conditions[conditionIndex].reason == 'Succeeded' or observedObj.status.conditions[conditionIndex].reason == 'ChartPullSucceeded' then
return true
end
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.observedSourceArtifactRevision ~= nil and statusItems[i].status.observedSourceArtifactRevision ~= '' then
desiredObj.status.observedSourceArtifactRevision = statusItems[i].status.observedSourceArtifactRevision
end
if statusItems[i].status ~= nil and statusItems[i].status.observedChartName ~= nil and statusItems[i].status.observedChartName ~= '' then
desiredObj.status.observedChartName = statusItems[i].status.observedChartName
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.observedSourceArtifactRevision = observedObj.status.observedSourceArtifactRevision
status.observedChartName = observedObj.status.observedChartName
status.conditions = observedObj.status.conditions
status.url = observedObj.status.url
status.artifact = observedObj.status.artifact
status.lastHandledReconcileAt = observedObj.status.lastHandledReconcileAt
return status
end
dependencyInterpretation:
luaScript: >
function GetDependencies(desiredObj)
dependentSecrets = {}
refs = {}
local idx = 1
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: HelmChart
metadata:
name: sample
namespace: test-helmchart
spec:
interval: 5m0s
chart: podinfo
reconcileStrategy: ChartVersion
sourceRef:
kind: HelmRepository
name: sample
version: '5.*'
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: HelmChart
metadata:
name: sample
namespace: test-helmchart
spec:
interval: 5m0s
chart: podinfo
reconcileStrategy: ChartVersion
sourceRef:
kind: HelmRepository
name: sample
version: '5.*'
suspend: true
verify:
provider: cosign
secretRef:
name: fake-cosign-public-keys
status:
artifact:
digest: sha256:6c3cc3b955bce1686036ae6822ee2ca0ef6ecb994e3f2d19eaf3ec03dcba84b3
lastUpdateTime: "2023-04-30T07:22:36Z"
path: helmchart/test-helmchart/sample/podinfo-5.2.1.tgz
revision: 5.2.1
size: 13418
url: http://source-controller.flux-system.svc.cluster.local./helmchart/test-helmchart/sample/podinfo-5.2.1.tgz
conditions:
- lastTransitionTime: "2023-04-30T07:22:36Z"
message: pulled 'podinfo' chart with version '5.2.1'
observedGeneration: 1
reason: ChartPullSucceeded
status: "True"
type: Ready
- lastTransitionTime: "2023-04-30T07:22:36Z"
message: pulled 'podinfo' chart with version '5.2.1'
observedGeneration: 1
reason: ChartPullSucceeded
status: "True"
type: ArtifactInStorage
observedChartName: podinfo
observedGeneration: 1
observedSourceArtifactRevision: sha256:61f94c20ee9417f222c3d30672724473ae50d406c8c097d80a8a6263c1384f69
url: http://source-controller.flux-system.svc.cluster.local./helmchart/test-helmchart/sample/latest.tar.gz
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
applied: true
clusterName: member1
health: Healthy
status:
artifact:
digest: sha256:6c3cc3b955bce1686036ae6822ee2ca0ef6ecb994e3f2d19eaf3ec03dcba84b3
lastUpdateTime: "2023-04-30T07:22:36Z"
path: helmchart/test-helmchart/sample/podinfo-5.2.1.tgz
revision: 5.2.1
size: 13418
url: http://source-controller.flux-system.svc.cluster.local./helmchart/test-helmchart/sample/podinfo-5.2.1.tgz
conditions:
- lastTransitionTime: "2023-04-30T07:22:36Z"
message: pulled 'podinfo' chart with version '5.2.1'
observedGeneration: 1
reason: ChartPullSucceeded
status: "True"
type: Ready
- lastTransitionTime: "2023-04-30T07:22:36Z"
message: pulled 'podinfo' chart with version '5.2.1'
observedGeneration: 1
reason: ChartPullSucceeded
status: "True"
type: ArtifactInStorage
observedChartName: podinfo
observedSourceArtifactRevision: sha256:61f94c20ee9417f222c3d30672724473ae50d406c8c097d80a8a6263c1384f69
url: http://source-controller.flux-system.svc.cluster.local./helmchart/test-helmchart/sample/latest.tar.gz
---
applied: true
clusterName: member3
health: Healthy
status:
artifact:
digest: sha256:6c3cc3b955bce1686036ae6822ee2ca0ef6ecb994e3f2d19eaf3ec03dcba84b3
lastUpdateTime: "2023-04-30T07:22:37Z"
path: helmchart/test-helmchart/sample/podinfo-5.2.1.tgz
revision: 5.2.1
size: 13418
url: http://source-controller.flux-system.svc.cluster.local./helmchart/test-helmchart/sample/podinfo-5.2.1.tgz
conditions:
- lastTransitionTime: "2023-04-30T07:22:37Z"
message: pulled 'podinfo' chart with version '5.2.1'
observedGeneration: 1
reason: ChartPullSucceeded
status: "True"
type: Ready
- lastTransitionTime: "2023-04-30T07:22:37Z"
message: pulled 'podinfo' chart with version '5.2.1'
observedGeneration: 1
reason: ChartPullSucceeded
status: "True"
type: ArtifactInStorage
observedChartName: podinfo
observedSourceArtifactRevision: sha256:61f94c20ee9417f222c3d30672724473ae50d406c8c097d80a8a6263c1384f69
url: http://source-controller.flux-system.svc.cluster.local./helmchart/test-helmchart/sample/latest.tar.gz