Skip to content

Commit 905755f

Browse files
authored
Merge pull request #35 from kleis-technology/feature/helm-charts
feature/helm charts
2 parents f1306cc + f7c108d commit 905755f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+971
-210
lines changed

README.md

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ docker compose up -d
4646
The API specification is available in the folder `openapi`.
4747
For a more interactive visualisation of the API, the `docker-compose`
4848
also spins up a swagger ui instance.
49-
Visit this [page](http://localhost) to explore the endpoints, DTOs and run example queries.
49+
Visit this [http://localhost](http://localhost) to explore the endpoints, DTOs and run example queries.
5050

5151
### Local build and run
5252

@@ -601,45 +601,24 @@ These models are specified under the folder `trusted_library`.
601601

602602
The models are written in the [LCA as CODE](https://lca-as-code.com) language.
603603
This is a domain-specific language designed for the need of lifecycle analysis.
604-
The models under the folder `trusted_library` are directly loaded in the server
604+
The models under the folder `trusted_library/lib` are directly loaded in the server
605605
to perform the assessments.
606606
A [tutorial](https://lca-as-code.com/book) is available if you want to learn
607607
more about the language itself.
608608
The source repository is available [here](https://github.com/kleis-technology/lcaac).
609609

610610
The folder `trusted_library` is organized as follows.
611-
612-
* `01-hardware` : this folder contains the PCR models for the functional units 1 to 4.
613-
* `02-pooling` : this folder contains the PCR models for the functional units 5 to 7.
614-
* `03-services` : this folder contains higher functional units.
611+
* `lib` : this folder contains the models written in [LCA as CODE](https://lca-as-code.com).
612+
* `inventory` : this folder contains inventory data (csv files)
615613

616614
Here is an illustration of this layering structure.
617615

618616
<img alt="sankey" src="assets/sankey.png" width=800/>
619617

620-
#### Configuring the models
621-
622-
You can read and edit the models in `trusted_library` with any text editor.
623-
Unless you need to customize one of the functional units, there is no need to actually modify the models.
624-
625-
The folder `trusted_library/data` contains inventory files (in CSV format),
626-
and associated emission factors. To adapt Cloud Assess you must fill in, at least,
627-
the following inventories
628-
629-
* `data/01-hardware/dc_inventory.csv` : this file lists the available datacenters.
630-
* `data/01-hardware/server_inventory.csv` : this file lists the available servers.
631-
* `data/01-hardware/network_inventory.csv` : this file lists the available network equipments.
632-
* `data/01-hardware/storage_inventory.csv` : this file lists the available storage equipments.
633-
634-
The following files should be filled with the relevant emission factors:
635-
636-
* `data/01-hardware/dc_impacts.csv`
637-
* `data/01-hardware/server_impacts.csv`
638-
* `data/01-hardware/network_impacts.csv`
639-
* `data/01-hardware/storage_impacts.csv`
640-
* `data/01-hardware/electricity_mix.csv`
618+
#### Configuring and deploying Cloud Assess
641619

642-
Note that the emission factors presented in this repository are mock values.
620+
Check out the [wiki](https://github.com/kleis-technology/cloud-assess/wiki/Deploying-Cloud-Assess)
621+
for a tutorial on how to configure and deploy Cloud Assess in a Kubernetes environment.
643622

644623
## License
645624

RELEASE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Release
2+
3+
Before releasing a new version, check that the Cloud Assess version
4+
is correctly set in
5+
- `build.gradle.kts`
6+
- `docker-compose.yaml`
7+
- `charts/cloud-assess/Chart.yaml`

build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ plugins {
1111
}
1212

1313
group = "org.cloud_assess"
14-
version = "2.0.1"
14+
version = "2.1.0"
1515

1616
java {
1717
sourceCompatibility = JavaVersion.VERSION_17
@@ -52,6 +52,8 @@ dependencies {
5252

5353
implementation("com.charleskorn.kaml:kaml:0.59.0")
5454
implementation("org.springframework.boot:spring-boot-starter-actuator")
55+
56+
implementation("org.apache.commons:commons-compress:1.28.0")
5557
}
5658

5759
tasks.withType<KotlinCompile> {

charts/cloud-assess/.helmignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/

charts/cloud-assess/Chart.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: v2
2+
name: cloud-assess
3+
description: A Helm chart for Kubernetes
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: 0.1.0
19+
20+
# This is the version number of the application being deployed. This version number should be
21+
# incremented each time you make changes to the application. Versions are not expected to
22+
# follow Semantic Versioning. They should reflect the version the application is using.
23+
# It is recommended to use it with quotes.
24+
appVersion: "v2.1.0"
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
1. Get the application URL by running these commands:
2+
{{- if .Values.httpRoute.enabled }}
3+
{{- if .Values.httpRoute.hostnames }}
4+
export APP_HOSTNAME={{ .Values.httpRoute.hostnames | first }}
5+
{{- else }}
6+
export APP_HOSTNAME=$(kubectl get --namespace {{(first .Values.httpRoute.parentRefs).namespace | default .Release.Namespace }} gateway/{{ (first .Values.httpRoute.parentRefs).name }} -o jsonpath="{.spec.listeners[0].hostname}")
7+
{{- end }}
8+
{{- if and .Values.httpRoute.rules (first .Values.httpRoute.rules).matches (first (first .Values.httpRoute.rules).matches).path.value }}
9+
echo "Visit http://$APP_HOSTNAME{{ (first (first .Values.httpRoute.rules).matches).path.value }} to use your application"
10+
11+
NOTE: Your HTTPRoute depends on the listener configuration of your gateway and your HTTPRoute rules.
12+
The rules can be set for path, method, header and query parameters.
13+
You can check the gateway configuration with 'kubectl get --namespace {{(first .Values.httpRoute.parentRefs).namespace | default .Release.Namespace }} gateway/{{ (first .Values.httpRoute.parentRefs).name }} -o yaml'
14+
{{- end }}
15+
{{- else if .Values.ingress.enabled }}
16+
{{- range $host := .Values.ingress.hosts }}
17+
{{- range .paths }}
18+
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
19+
{{- end }}
20+
{{- end }}
21+
{{- else if contains "NodePort" .Values.service.type }}
22+
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "cloud-assess.fullname" . }})
23+
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
24+
echo http://$NODE_IP:$NODE_PORT
25+
{{- else if contains "LoadBalancer" .Values.service.type }}
26+
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
27+
You can watch its status by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "cloud-assess.fullname" . }}'
28+
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "cloud-assess.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
29+
echo http://$SERVICE_IP:{{ .Values.service.port }}
30+
{{- else if contains "ClusterIP" .Values.service.type }}
31+
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "cloud-assess.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
32+
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
33+
echo "Visit http://127.0.0.1:8080 to use your application"
34+
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
35+
{{- end }}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "cloud-assess.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "cloud-assess.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "cloud-assess.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "cloud-assess.labels" -}}
37+
helm.sh/chart: {{ include "cloud-assess.chart" . }}
38+
{{ include "cloud-assess.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- end }}
44+
45+
{{/*
46+
Selector labels
47+
*/}}
48+
{{- define "cloud-assess.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "cloud-assess.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
52+
53+
{{/*
54+
Create the name of the service account to use
55+
*/}}
56+
{{- define "cloud-assess.serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "cloud-assess.fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ include "cloud-assess.fullname" . }}
5+
labels:
6+
{{- include "cloud-assess.labels" . | nindent 4 }}
7+
spec:
8+
{{- if not .Values.autoscaling.enabled }}
9+
replicas: {{ .Values.replicaCount }}
10+
{{- end }}
11+
selector:
12+
matchLabels:
13+
{{- include "cloud-assess.selectorLabels" . | nindent 6 }}
14+
template:
15+
metadata:
16+
annotations:
17+
checksum/inventory.zip: {{ .Values.lca.archive.inventory.content | sha256sum }}
18+
{{- with .Values.podAnnotations }}
19+
{{- toYaml . | nindent 8 }}
20+
{{- end }}
21+
labels:
22+
{{- include "cloud-assess.labels" . | nindent 8 }}
23+
{{- with .Values.podLabels }}
24+
{{- toYaml . | nindent 8 }}
25+
{{- end }}
26+
spec:
27+
{{- with .Values.imagePullSecrets }}
28+
imagePullSecrets:
29+
{{- toYaml . | nindent 8 }}
30+
{{- end }}
31+
serviceAccountName: {{ include "cloud-assess.serviceAccountName" . }}
32+
{{- with .Values.podSecurityContext }}
33+
securityContext:
34+
{{- toYaml . | nindent 8 }}
35+
{{- end }}
36+
containers:
37+
- name: {{ .Chart.Name }}
38+
{{- with .Values.securityContext }}
39+
securityContext:
40+
{{- toYaml . | nindent 12 }}
41+
{{- end }}
42+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
43+
imagePullPolicy: {{ .Values.image.pullPolicy }}
44+
env:
45+
- name: LCA_DIRECTORY
46+
value: {{ .Values.lca.directory }}
47+
- name: LCA_LIB_DIRECTORY
48+
value: {{ .Values.lca.lib.directory }}
49+
- name: LCA_ARCHIVE_DIRECTORY
50+
value: {{ .Values.lca.archive.directory }}
51+
- name: LCA_INVENTORY_ZIP
52+
value: {{ .Values.lca.archive.inventory.filename }}
53+
- name: LCA_INVENTORY_DIRECTORY
54+
value: {{ .Values.lca.inventory.directory }}
55+
ports:
56+
- name: http
57+
containerPort: {{ .Values.service.port }}
58+
protocol: TCP
59+
{{- with .Values.livenessProbe }}
60+
livenessProbe:
61+
{{- toYaml . | nindent 12 }}
62+
{{- end }}
63+
{{- with .Values.readinessProbe }}
64+
readinessProbe:
65+
{{- toYaml . | nindent 12 }}
66+
{{- end }}
67+
{{- with .Values.resources }}
68+
resources:
69+
{{- toYaml . | nindent 12 }}
70+
{{- end }}
71+
volumeMounts:
72+
- name: archive
73+
mountPath: {{ .Values.lca.directory }}/{{ .Values.lca.archive.directory }}
74+
volumes:
75+
- name: archive
76+
configMap:
77+
name: {{ .Values.lca.archive.configMapName }}
78+
{{- with .Values.nodeSelector }}
79+
nodeSelector:
80+
{{- toYaml . | nindent 8 }}
81+
{{- end }}
82+
{{- with .Values.affinity }}
83+
affinity:
84+
{{- toYaml . | nindent 8 }}
85+
{{- end }}
86+
{{- with .Values.tolerations }}
87+
tolerations:
88+
{{- toYaml . | nindent 8 }}
89+
{{- end }}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{{- if .Values.autoscaling.enabled }}
2+
apiVersion: autoscaling/v2
3+
kind: HorizontalPodAutoscaler
4+
metadata:
5+
name: {{ include "cloud-assess.fullname" . }}
6+
labels:
7+
{{- include "cloud-assess.labels" . | nindent 4 }}
8+
spec:
9+
scaleTargetRef:
10+
apiVersion: apps/v1
11+
kind: Deployment
12+
name: {{ include "cloud-assess.fullname" . }}
13+
minReplicas: {{ .Values.autoscaling.minReplicas }}
14+
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
15+
metrics:
16+
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
17+
- type: Resource
18+
resource:
19+
name: cpu
20+
target:
21+
type: Utilization
22+
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
23+
{{- end }}
24+
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
25+
- type: Resource
26+
resource:
27+
name: memory
28+
target:
29+
type: Utilization
30+
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
31+
{{- end }}
32+
{{- end }}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{{- if .Values.httpRoute.enabled -}}
2+
{{- $fullName := include "cloud-assess.fullname" . -}}
3+
{{- $svcPort := .Values.service.port -}}
4+
apiVersion: gateway.networking.k8s.io/v1
5+
kind: HTTPRoute
6+
metadata:
7+
name: {{ $fullName }}
8+
labels:
9+
{{- include "cloud-assess.labels" . | nindent 4 }}
10+
{{- with .Values.httpRoute.annotations }}
11+
annotations:
12+
{{- toYaml . | nindent 4 }}
13+
{{- end }}
14+
spec:
15+
parentRefs:
16+
{{- with .Values.httpRoute.parentRefs }}
17+
{{- toYaml . | nindent 4 }}
18+
{{- end }}
19+
{{- with .Values.httpRoute.hostnames }}
20+
hostnames:
21+
{{- toYaml . | nindent 4 }}
22+
{{- end }}
23+
rules:
24+
{{- range .Values.httpRoute.rules }}
25+
{{- with .matches }}
26+
- matches:
27+
{{- toYaml . | nindent 8 }}
28+
{{- end }}
29+
{{- with .filters }}
30+
filters:
31+
{{- toYaml . | nindent 8 }}
32+
{{- end }}
33+
backendRefs:
34+
- name: {{ $fullName }}
35+
port: {{ $svcPort }}
36+
weight: 1
37+
{{- end }}
38+
{{- end }}

0 commit comments

Comments
 (0)