mirror of
https://github.com/truecharts/library-charts.git
synced 2026-07-05 04:36:23 -03:00
**Description** While current refactor is already a huge upgrade, we want to restructure so multi-pod can be supported from the start as well. **⚙️ Type of change** - [X] ⚙️ Feature/App addition - [X] 🪛 Bugfix - [X] ⚠️ Breaking change (fix or feature that would cause existing functionality to not work as expected) - [X] 🔃 Refactor of current code **🧪 How Has This Been Tested?** <!-- Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration --> **📃 Notes:** <!-- Please enter any other relevant information here --> **✔️ Checklist:** - [ ] ⚖️ My code follows the style guidelines of this project - [ ] 👀 I have performed a self-review of my own code - [ ] #️⃣ I have commented my code, particularly in hard-to-understand areas - [ ] 📄 I have made corresponding changes to the documentation - [ ] ⚠️ My changes generate no new warnings - [ ] 🧪 I have added tests to this description that prove my fix is effective or that my feature works - [ ] ⬆️ I increased versions for any altered app according to semantic versioning **➕ App addition** If this PR is an app addition please make sure you have done the following. - [ ] 🪞 I have opened a PR on [truecharts/containers](https://github.com/truecharts/containers) adding the container to TrueCharts mirror repo. - [ ] 🖼️ I have added an icon in the Chart's root directory called `icon.png` --- _Please don't blindly check all the boxes. Read them and only check those that apply. Those checkboxes are there for the reviewer to see what is this all about and the status of this PR with a quick glance._ --------- Co-authored-by: Stavros kois <s.kois@outlook.com>
48 lines
1.8 KiB
Smarty
48 lines
1.8 KiB
Smarty
{{/* Service - Get Selected Service */}}
|
|
{{/* Call this template:
|
|
{{ include "tc.v1.common.lib.helpers.getSelectedServiceValues" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
|
|
objectData: The object data of the service
|
|
rootCtx: The root context of the chart.
|
|
*/}}
|
|
|
|
{{- define "tc.v1.common.lib.helpers.getSelectedServiceValues" -}}
|
|
{{- $rootCtx := .rootCtx -}}
|
|
{{- $objectData := .objectData -}}
|
|
{{- $caller := .caller -}}
|
|
|
|
{{- $serviceValues := dict -}}
|
|
{{- with $objectData.targetSelector -}}
|
|
{{- $serviceValues = mustDeepCopy (get $rootCtx.Values.service .) -}}
|
|
|
|
{{- if not $serviceValues -}}
|
|
{{- fail (printf "%s - Selected service [%s] is not defined" $caller .) -}}
|
|
{{- end -}}
|
|
|
|
{{- if not $serviceValues.enabled -}}
|
|
{{- fail (printf "%s - Selected service [%s] is not enabled" $caller .) -}}
|
|
{{- end -}}
|
|
|
|
{{/* While we know the shortName from targetSelector, let's set it explicitly
|
|
So service can reference this directly, to match the behaviour of a service
|
|
without targetSelector defined (assumes "use primary") */}}
|
|
{{- $_ := set $serviceValues "shortName" . -}}
|
|
{{- else -}}
|
|
|
|
{{/* If no targetSelector is defined, we assume the service is using the primary service */}}
|
|
{{/* Also no need to check for multiple primaries here, it's already done on the service validation */}}
|
|
{{- range $serviceName, $service := $rootCtx.Values.service -}}
|
|
{{- if $service.enabled -}}
|
|
{{- if $service.primary -}}
|
|
{{- $serviceValues = mustDeepCopy $service -}}
|
|
{{/* Set the shortName so service can use this on selector */}}
|
|
{{- $_ := set $serviceValues "shortName" $serviceName -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
|
|
{{- end -}}
|
|
|
|
{{/* Return values in Json, to preserve types */}}
|
|
{{ $serviceValues | toJson }}
|
|
{{- end -}}
|