From 76055ebd6c851f93b368775efa20ae8ca4be1cbc Mon Sep 17 00:00:00 2001 From: yasuenag Date: Thu, 21 Dec 2023 09:48:54 +0900 Subject: [PATCH 1/2] Support location source setting in Helm chart Signed-off-by: Yasumasa Suenaga --- docs/overview.md | 34 +++++++++++++++++++ helm-chart/templates/configmap.yaml | 13 +++++++ helm-chart/templates/deployment.yaml | 15 ++++++++ helm-chart/values.yaml | 34 +++++++++++++++++++ .../src/LocationSource.cs | 2 +- 5 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 helm-chart/templates/configmap.yaml diff --git a/docs/overview.md b/docs/overview.md index 8ac7fdac2..931d508fd 100644 --- a/docs/overview.md +++ b/docs/overview.md @@ -355,6 +355,40 @@ appsettings: |- } } } + +# Location source +# Location data will be deployed into /app/location-sources/json . +locationSources: + enabled: false +# files: +# - fileName: custom-locations-1.json +# locations: |- +# { +# "east": { +# "Latitude": "35.68", +# "Longitude": "139.77", +# "Name": "eastdc" +# }, +# "west": { +# "Latitude": "34.6939", +# "Longitude": "135.5022", +# "Name": "westdc" +# } +# } +# - fileName: custom-locations-2.json +# locations: |- +# { +# "north": { +# "Latitude": "35.68", +# "Longitude": "139.77", +# "Name": "northdc" +# }, +# "south": { +# "Latitude": "34.6939", +# "Longitude": "135.5022", +# "Name": "southdc" +# } +# } ``` The video in below is demonstration to install Carbon Aware SDK via Helm. Note that installing the SDK from local directory ( ~/github-forked/carbon-aware-sdk/helm-chart ), not an OCI container. diff --git a/helm-chart/templates/configmap.yaml b/helm-chart/templates/configmap.yaml new file mode 100644 index 000000000..c314df0e0 --- /dev/null +++ b/helm-chart/templates/configmap.yaml @@ -0,0 +1,13 @@ +{{- if .Values.locationSources.enabled }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: location-sources + namespace: {{ $.Release.Namespace }} + labels: + {{- include "carbon-aware-sdk.labels" . | nindent 4 }} +data: + {{- range .Values.locationSources.files }} + {{ .fileName }}: {{- toYaml .locations | nindent 4 }} + {{- end }} +{{- end }} diff --git a/helm-chart/templates/deployment.yaml b/helm-chart/templates/deployment.yaml index 3a9891b36..cec413296 100644 --- a/helm-chart/templates/deployment.yaml +++ b/helm-chart/templates/deployment.yaml @@ -46,6 +46,11 @@ spec: mountPath: /app/appsettings.json subPath: appsettings.json readOnly: true + {{- if .Values.locationSources.enabled }} + - name: location-sources + mountPath: /app/location-sources/json + readOnly: true + {{- end }} livenessProbe: httpGet: path: /health @@ -60,6 +65,16 @@ spec: - name: appsettings secret: secretName: appsettings + {{- if .Values.locationSources.enabled }} + - name: location-sources + configMap: + name: location-sources + items: + {{- range .Values.locationSources.files }} + - key: {{ .fileName }} + path: {{ .fileName }} + {{- end }} + {{- end }} {{- with .Values.nodeSelector }} nodeSelector: {{- toYaml . | nindent 8 }} diff --git a/helm-chart/values.yaml b/helm-chart/values.yaml index 3d32c9266..452ef6a21 100644 --- a/helm-chart/values.yaml +++ b/helm-chart/values.yaml @@ -108,3 +108,37 @@ appsettings: |- } } } + +# Location source +# Location data will be deployed into /app/location-sources/json . +locationSources: + enabled: false +# files: +# - fileName: custom-locations-1.json +# locations: |- +# { +# "east": { +# "Latitude": "35.68", +# "Longitude": "139.77", +# "Name": "eastdc" +# }, +# "west": { +# "Latitude": "34.6939", +# "Longitude": "135.5022", +# "Name": "westdc" +# } +# } +# - fileName: custom-locations-2.json +# locations: |- +# { +# "north": { +# "Latitude": "35.68", +# "Longitude": "139.77", +# "Name": "northdc" +# }, +# "south": { +# "Latitude": "34.6939", +# "Longitude": "135.5022", +# "Name": "southdc" +# } +# } diff --git a/src/CarbonAware.LocationSources/src/LocationSource.cs b/src/CarbonAware.LocationSources/src/LocationSource.cs index de96cca8a..793b09dd8 100644 --- a/src/CarbonAware.LocationSources/src/LocationSource.cs +++ b/src/CarbonAware.LocationSources/src/LocationSource.cs @@ -109,7 +109,7 @@ private IEnumerable DiscoverFiles() return Array.Empty(); } _logger.LogInformation($"{files.Count()} files discovered"); - return files.Select(x => x.Substring(pathCombined.Length + 1)).Select(n => new LocationSourceFile { DataFileLocation = n }); + return files.Select(x => x.Substring(pathCombined.Length + 1)).Where(n => !n.StartsWith("..")).Select(n => new LocationSourceFile { DataFileLocation = n }); } private void AddToLocationMap(string key, NamedGeoposition data, string sourceFile, Dictionary keyCounter) From 98c45436744ef04d1d9e8b652ae7de5ec4a1b759 Mon Sep 17 00:00:00 2001 From: Yasumasa Suenaga Date: Tue, 13 Feb 2024 08:44:32 +0900 Subject: [PATCH 2/2] Up Helm chart version to 1.1.0 Signed-off-by: Yasumasa Suenaga --- helm-chart/Chart.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helm-chart/Chart.yaml b/helm-chart/Chart.yaml index be8609521..fadfb8f70 100644 --- a/helm-chart/Chart.yaml +++ b/helm-chart/Chart.yaml @@ -15,7 +15,7 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 1.0.0 +version: 1.1.0 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to