-
Notifications
You must be signed in to change notification settings - Fork 833
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add customizations for source.toolkit.fluxcd.io/v1beta2/HelmChart
Signed-off-by: yike21 <yike21@qq.com>
- Loading branch information
Showing
4 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
...rty/resourcecustomizations/source.toolkit.fluxcd.io/v1beta2/HelmChart/customizations.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
13 changes: 13 additions & 0 deletions
13
...customizations/source.toolkit.fluxcd.io/v1beta2/HelmChart/testdata/desired-helmchart.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.*' |
43 changes: 43 additions & 0 deletions
43
...ustomizations/source.toolkit.fluxcd.io/v1beta2/HelmChart/testdata/observed-helmchart.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
55 changes: 55 additions & 0 deletions
55
...sourcecustomizations/source.toolkit.fluxcd.io/v1beta2/HelmChart/testdata/status-file.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |