diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae02570 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +release/ \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..3507a59 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,5 @@ +include: + - project: resengit/gitlab/pipeline-helpers + ref: main + file: /pipelines/helm-chart.yaml + diff --git a/Chart.yaml b/Chart.yaml new file mode 100644 index 0000000..d8e7ac7 --- /dev/null +++ b/Chart.yaml @@ -0,0 +1,25 @@ +# ICOS Scaphandre +# Copyright © 2022-2024 National and Kapodistrian University of Athens +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# This work has received funding from the European Union's HORIZON research +# and innovation programme under grant agreement No. 101070177. + +apiVersion: v1 +appVersion: 0.1.1 +description: A Helm chart for Scaphandre electrical power consumption agent +home: https://github.com/hubblo-org/scaphandre +name: scaphandre +version: 2.0.2 + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1d3c5da --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2022-2024 National and Kapodistrian University of Athens + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..fe38da8 --- /dev/null +++ b/NOTICE @@ -0,0 +1,4 @@ +ICOS Scaphandre +Copyright © 2022-2024 National and Kapodistrian University of Athens + +🇪🇺 This work has received funding from the European Union's HORIZON research and innovation programme under grant agreement No. 101070177. diff --git a/README.md b/README.md new file mode 100644 index 0000000..b92d882 --- /dev/null +++ b/README.md @@ -0,0 +1,54 @@ +# ICOS Scaphandre + +## Description +Scaphandre is a monitoring agent, dedicated to capturing energy consumption metrics. Its primary purpose is to facilitate the measurement and understanding of energy consumption patterns in technological services, which is crucial for steering the tech industry towards greater sustainability. + +Scaphandre exposes a wide array of metrics, which can be found [here](https://hubblo-org.github.io/scaphandre-documentation/references/metrics.html) + +For more detailed information about the Scaphandre project, please refer to:: +- The [GitHub repository of the Scaphandre project](https://github.com/hubblo-org/scaphandre/tree/main) +- The [documentation site of Scaphandre](https://docs.rs/scaphandre/latest/scaphandre/) +- The [simplified guide for Scaphandre installation](https://hubblo-org.github.io/scaphandre-documentation/index.html) + +Within the ICOS suite, Scaphandre is utilized alongside the ICOS Telemetry. It is compatible with all CPU architectures except those in the ARM family. The metrics exposed from Scaphandre are scraped from Prometheus/Thanos of ICOS Telemetry Controller. + +## Build, Package, Deploy and Test Scaphandre + +### Build +The main repository for Scaphandre is located [here](https://github.com/hubblo-org/scaphandre/tree/main). +From there, you can either create a custom image or use the [official Scaphandre image](https://hubblo-org.github.io/scaphandre-documentation/tutorials/kubernetes.html). + +### Packaging +To begin the packaging process after cloning the repository, use the following command: +```shell +helm package ./ -d ./releases +``` +This command will create a new release, based on the values specified in the ```Chart.yaml``` file and the appropriate image set in the ```values.yaml``` file and place it in the ```releases``` folder. + +### Deploy +Deploy the created release with ```helm``` to the desired Kubernetes cluster using the following command: +```shell +helm install {{release-name}} +``` +The Helm daemonset will deploy a Scaphandre instance to all available nodes of the cluster. During deployment, you may use the following parameters if necessary: +| Name |Description | Value | +|----------------------------|----------------------------------------------------------------------------------------|-------| +| `serviceMonitor.enabled` | Create ServiceMonitor Resource for scraping metrics using PrometheusOperator | false | +| `serviceMonitor.namespace` | The namespace in which the ServiceMonitor will be created (default is to use the same namespace as the Helm chart) | `default` | +| `serviceMonitor.interval` | The interval at which metrics should be scraped | `30s` | + +### Testing +Scaphandre tests are automatically triggered during the deployment process: + +- ```test-scaphandre-node-cpu-arch-pre-install```: This test is executed before Scaphandre installation on each node to ensure that the CPU architecture of each node is not ARM. The test will fail if all of the nodes have an ARM architecture. + +- ```test-scaphandre-status-check```: This test runs after the deployment of each Scaphandre instance to verify that each pod is in a running state. The test will fail if all pods are not in a running state. You can re-run the test if necessary with the following command: +```shell +helm test {{release-name}} +``` + +# Legal +The ICOS Scaphandre is released under the Apache 2.0 license. +Copyright © 2022-2024 National and Kapodistrian University of Athens. All rights reserved. + +🇪🇺 This work has received funding from the European Union's HORIZON research and innovation programme under grant agreement No. 101070177. diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl new file mode 100644 index 0000000..f8aba16 --- /dev/null +++ b/templates/_helpers.tpl @@ -0,0 +1,45 @@ +{{- /* + * ICOS Scaphandre + * Copyright © 2022-2024 National and Kapodistrian University of Athens + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This work has received funding from the European Union's HORIZON research + * and innovation programme under grant agreement No. 101070177. + */ -}} + +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "scaphandre.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "scaphandre.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Common labels +*/}} +{{- define "labels.common" -}} +app.kubernetes.io/name: {{ include "scaphandre.name" . | quote }} +app.kubernetes.io/instance: {{ .Release.Name | quote }} +app.kubernetes.io/version: {{ .Chart.Version | quote }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +helm.sh/chart: {{ include "scaphandre.chart" . }} +{{- end -}} diff --git a/templates/daemonset.yaml b/templates/daemonset.yaml new file mode 100644 index 0000000..b3d8f23 --- /dev/null +++ b/templates/daemonset.yaml @@ -0,0 +1,102 @@ +{{- /* + * ICOS Scaphandre + * Copyright © 2022-2024 National and Kapodistrian University of Athens + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This work has received funding from the European Union's HORIZON research + * and innovation programme under grant agreement No. 101070177. + */ -}} + +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: {{ template "scaphandre.name" . }} + labels: + {{- include "labels.common" . | nindent 4 }} +spec: + updateStrategy: + type: RollingUpdate + selector: + matchLabels: + app.kubernetes.io/name: {{ template "scaphandre.name" . }} + template: + metadata: + name: {{ template "scaphandre.name" . }} + labels: + {{- include "labels.common" . | nindent 8 }} + annotations: + {{- toYaml .Values.annotations | nindent 8 }} + spec: + containers: + - name: {{ template "scaphandre.name" . }} + image: "{{ .Values.image.name }}:{{ .Values.image.tag }}" + args: + # - "--vm" + {{- range $key, $value := .Values.scaphandre.args }} + {{- if $value }} + - --{{ $key }}={{ $value }} + {{- else }} + - --{{ $key }} + {{- end }} + {{- end }} + - {{ .Values.scaphandre.command }} + {{- range $key, $value := .Values.scaphandre.extraArgs }} + {{- if $value }} + - --{{ $key }}={{ $value }} + {{- else }} + - --{{ $key }} + {{- end }} + {{- end }} + env: + {{- if .Values.scaphandre.rustBacktrace }} + - name: RUST_BACKTRACE + value: '{{ .Values.scaphandre.rustBacktrace }}' + {{- end }} + ports: + - name: metrics + containerPort: {{ .Values.port }} + resources: +{{ toYaml .Values.resources | indent 10 }} + volumeMounts: + - mountPath: /proc + name: proc + readOnly: false + - mountPath: /sys/class/powercap + name: powercap + readOnly: false + livenessProbe: + httpGet: + path: /metrics + port: 8080 + initialDelaySeconds: 120 + periodSeconds: 60 + timeoutSeconds: 9 + failureThreshold: 5 + securityContext: + privileged: true + runAsUser: {{ .Values.userID }} + runAsGroup: {{ .Values.userGroup }} + serviceAccountName: {{ template "scaphandre.name" . }} + tolerations: + # Tolerate all taints for observability + - operator: "Exists" + volumes: + - hostPath: + path: /proc + type: "Directory" + name: proc + - hostPath: + path: /sys/class/powercap + type: "Directory" + name: powercap diff --git a/templates/rbac.yaml b/templates/rbac.yaml new file mode 100644 index 0000000..0e13b7f --- /dev/null +++ b/templates/rbac.yaml @@ -0,0 +1,59 @@ +{{- /* + * ICOS Scaphandre + * Copyright © 2022-2024 National and Kapodistrian University of Athens + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This work has received funding from the European Union's HORIZON research + * and innovation programme under grant agreement No. 101070177. + */ -}} + +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: {{ template "scaphandre.name" . }} + labels: + {{- include "labels.common" . | nindent 4 }} +subjects: +- kind: ServiceAccount + name: {{ template "scaphandre.name" . }} + namespace: {{ .Release.Namespace }} +roleRef: + kind: ClusterRole + name: {{ template "scaphandre.name" . }} + apiGroup: rbac.authorization.k8s.io +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ template "scaphandre.name" . }} + labels: + {{- include "labels.common" . | nindent 4 }} +rules: +- apiGroups: + - extensions + resources: + - podsecuritypolicies + resourceNames: + - {{ .Chart.Name }} + verbs: + - "use" +- apiGroups: + - "" + resources: + - pods + - nodes + verbs: + - list + - watch + - get diff --git a/templates/service-account.yaml b/templates/service-account.yaml new file mode 100644 index 0000000..b0fa983 --- /dev/null +++ b/templates/service-account.yaml @@ -0,0 +1,26 @@ +{{- /* + * ICOS Scaphandre + * Copyright © 2022-2024 National and Kapodistrian University of Athens + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This work has received funding from the European Union's HORIZON research + * and innovation programme under grant agreement No. 101070177. + */ -}} + +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ template "scaphandre.name" . }} + labels: + {{- include "labels.common" . | nindent 4 }} diff --git a/templates/service.yaml b/templates/service.yaml new file mode 100644 index 0000000..773ace6 --- /dev/null +++ b/templates/service.yaml @@ -0,0 +1,42 @@ +{{- /* + * ICOS Scaphandre + * Copyright © 2022-2024 National and Kapodistrian University of Athens + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This work has received funding from the European Union's HORIZON research + * and innovation programme under grant agreement No. 101070177. + */ -}} + +apiVersion: v1 +kind: Service +metadata: + name: {{ template "scaphandre.name" . }} + labels: + app.kubernetes.io/name: {{ template "scaphandre.name" . }} + annotations: + telemetry.icos.eu/scrape: "true" + telemetry.icos.eu/interval: "60s" + telemetry.icos.eu/timeout: "10s" + telemetry.icos.eu/scheme: "http" + telemetry.icos.eu/path: /metrics + telemetry.icos.eu/port: "{{ .Values.port }}" +spec: + type: NodePort + ports: + - port: {{ .Values.port }} + name: metrics + targetPort: metrics + nodePort: {{ .Values.nodePort }} + selector: + app.kubernetes.io/name: {{ template "scaphandre.name" . }} diff --git a/templates/tests/test-scaphandre-node-cpu-arch-pre-install.yaml b/templates/tests/test-scaphandre-node-cpu-arch-pre-install.yaml new file mode 100644 index 0000000..32fcb5b --- /dev/null +++ b/templates/tests/test-scaphandre-node-cpu-arch-pre-install.yaml @@ -0,0 +1,72 @@ +{{- /* + * ICOS Scaphandre + * Copyright © 2022-2024 National and Kapodistrian University of Athens + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This work has received funding from the European Union's HORIZON research + * and innovation programme under grant agreement No. 101070177. + */ -}} + +apiVersion: batch/v1 +kind: Job +metadata: + name: "{{ .Release.Name }}-node-cpu-arch-pre-install" + labels: + {{- include "labels.common" . | nindent 4 }} + annotations: + "helm.sh/hook": pre-install + "helm.sh/hook-weight": "1" + "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded,hook-failed +spec: + template: + spec: + containers: + - name: main + image: bitnami/kubectl:latest + command: + - "/bin/bash" + - "-c" + args: + - | + ALL_NODES=$(kubectl get nodes -o jsonpath='{.items[*].metadata.name}') + TOTAL_NODES=$(echo "$ALL_NODES" | wc -w) + ARM_NODES=0 + ARM_NODE_NAMES="" + + for NODE in $ALL_NODES; do + NODE_ARCH=$(kubectl get node $NODE -o jsonpath='{.metadata.labels.kubernetes\.io/arch}') + echo "Node $NODE architecture is: $NODE_ARCH" + + # Check if the node architecture is ARM or ARM-like + if [[ "$NODE_ARCH" == "arm64" || "$NODE_ARCH" == "arm" ]]; then + ARM_NODES=$((ARM_NODES + 1)) + ARM_NODE_NAMES="$ARM_NODE_NAMES $NODE" + fi + done + + # Display ARM nodes if any + if [ $ARM_NODES -gt 0 ]; then + echo "ARM architecture nodes: $ARM_NODE_NAMES" + fi + + # Only fail if all nodes are ARM or ARM-like architectures + if [ $ARM_NODES -eq $TOTAL_NODES ]; then + echo "Test failed: All nodes are on ARM or ARM-like architectures." + exit 1 + else + echo "All or some nodes have non-ARM architectures." + exit 0 + fi + restartPolicy: Never + backoffLimit: 1 diff --git a/templates/tests/test-scaphandre-status-check.yaml b/templates/tests/test-scaphandre-status-check.yaml new file mode 100644 index 0000000..d76f63f --- /dev/null +++ b/templates/tests/test-scaphandre-status-check.yaml @@ -0,0 +1,71 @@ +{{- /* + * ICOS Scaphandre + * Copyright © 2022-2024 National and Kapodistrian University of Athens + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This work has received funding from the European Union's HORIZON research + * and innovation programme under grant agreement No. 101070177. + */ -}} + +apiVersion: batch/v1 +kind: Job +metadata: + name: "{{ .Release.Name }}-status-check" + labels: + {{- include "labels.common" . | nindent 4 }} + annotations: + "helm.sh/hook": post-install,post-upgrade,test + "helm.sh/hook-weight": "1" + "helm.sh/hook-delete-policy": hook-succeeded,hook-failed +spec: + template: + spec: + serviceAccountName: {{ template "scaphandre.name" . }} # Ensure this account has permissions to get pods + restartPolicy: Never + containers: + - name: check-status + image: bitnami/kubectl:latest + command: + - "/bin/sh" + - "-c" + args: + - | + sleep 10 + + # Get all Scaphandre pods and their status + PODS=$(kubectl get pods --all-namespaces -l "app.kubernetes.io/name={{ template "scaphandre.name" . }}" -o jsonpath="{range .items[*]}{.metadata.name}{'\t'}{.status.phase}{'\n'}{end}") + echo "Checking Scaphandre pods status..." + echo "$PODS" + + # Count the number of pods in each status + TOTAL=$(echo "$PODS" | wc -l) + RUNNING=$(echo "$PODS" | grep -c 'Running') + SUCCEEDED=$(echo "$PODS" | grep -c 'Succeeded') + + # Determine test result based on pod statuses + if [ $RUNNING -eq 0 ] && [ $SUCCEEDED -eq 0 ]; then + echo "All Scaphandre pods have failed." + exit 1 + elif [ $((RUNNING + SUCCEEDED)) -eq $TOTAL ]; then + echo "All Scaphandre pods are successfully running or completed." + exit 0 + else + FAILED_PODS=$(echo "$PODS" | grep -vE 'Running|Succeeded') + echo "Some Scaphandre pods are not in a healthy state. Review the following pod statuses:" + echo "$FAILED_PODS" + exit 0 + fi + + exit 0 + backoffLimit: 3 \ No newline at end of file diff --git a/values.yaml b/values.yaml new file mode 100644 index 0000000..23bcf59 --- /dev/null +++ b/values.yaml @@ -0,0 +1,49 @@ +# ICOS Scaphandre +# Copyright © 2022-2024 National and Kapodistrian University of Athens +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# This work has received funding from the European Union's HORIZON research +# and innovation programme under grant agreement No. 101070177. + +image: + name: menelaoszetas/icos_scaphandre + tag: latest + +port: 8080 +nodePort: 30080 + +resources: + limits: + memory: 256Mi + requests: + cpu: 75m + memory: 128Mi + +scaphandre: + command: prometheus + args: {} + extraArgs: + containers: {} +# rustBacktrace: '1' + +# Run as root user to get proper permissions +userID: 0 +groupID: 0 + +serviceMonitor: + # Specifies whether ServiceMonitor for Prometheus operator should be created + enabled: true + interval: 1m + # Specifies namespace, where ServiceMonitor should be installed + namespace: icos-system