Skip to content

Commit

Permalink
Merge pull request #449 from YaSuenag/pr/helm-location-sources
Browse files Browse the repository at this point in the history
Support location source setting in Helm chart
  • Loading branch information
danuw authored Feb 13, 2024
2 parents f5a58db + 98c4543 commit b45c456
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 2 deletions.
34 changes: 34 additions & 0 deletions docs/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,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.
Expand Down
2 changes: 1 addition & 1 deletion helm-chart/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions helm-chart/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
15 changes: 15 additions & 0 deletions helm-chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
Expand Down
34 changes: 34 additions & 0 deletions helm-chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
# }
# }
2 changes: 1 addition & 1 deletion src/CarbonAware.LocationSources/src/LocationSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private IEnumerable<LocationSourceFile> DiscoverFiles()
return Array.Empty<LocationSourceFile>();
}
_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<string, int> keyCounter)
Expand Down

0 comments on commit b45c456

Please sign in to comment.