From 3ba1840f90f014191b7f26b356fc2a1566aca456 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ars=C3=A8ne=20Fougerouse?= Date: Tue, 16 Jan 2024 18:00:45 +0100 Subject: [PATCH 1/3] feat: add percentage save calcul MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Arsène Fougerouse --- src/components/ConsumptionCalculator.tsx | 85 ++++++++++++------------ 1 file changed, 43 insertions(+), 42 deletions(-) diff --git a/src/components/ConsumptionCalculator.tsx b/src/components/ConsumptionCalculator.tsx index 241a1b3..f65ecdd 100644 --- a/src/components/ConsumptionCalculator.tsx +++ b/src/components/ConsumptionCalculator.tsx @@ -1,36 +1,51 @@ -import React from 'react'; -import Decimal from 'decimal.js-light'; +import React from "react"; +import Decimal from "decimal.js-light"; -import clsx from 'clsx'; -import styles from './ConsumptionCalculator.module.css'; +import clsx from "clsx"; +import styles from "./ConsumptionCalculator.module.css"; export default function ConsumptionCalculator() { const [co2PerPod, setCO2PerPod] = React.useState(new Decimal(11)); const [numberOfPodsTotal, setNumberOfPods] = React.useState(new Decimal(100)); - const [numberOfPodsSleeped, setNumberOfSleepedPods] = React.useState(new Decimal(100)); - const [numberOfHourSleepInWeek, setNumberOfHourSleepInWeek] = React.useState(new Decimal(128)); + const [numberOfPodsSleeped, setNumberOfSleepedPods] = React.useState( + new Decimal(100) + ); + const [numberOfHourSleepInWeek, setNumberOfHourSleepInWeek] = React.useState( + new Decimal(128) + ); const resultWithKubeGreen = React.useMemo( - () => calculateCO2WeekConsumption( - co2PerPod, - numberOfPodsTotal, - numberOfPodsSleeped, - numberOfHourSleepInWeek, - ), - [co2PerPod, numberOfPodsTotal, numberOfPodsSleeped, numberOfHourSleepInWeek], + () => + calculateCO2WeekConsumption( + co2PerPod, + numberOfPodsTotal, + numberOfPodsSleeped, + numberOfHourSleepInWeek + ), + [co2PerPod, numberOfPodsTotal, numberOfPodsSleeped, numberOfHourSleepInWeek] ); const resultWithoutKubeGreen = React.useMemo( - () => calculateCO2WeekConsumption( - co2PerPod, - numberOfPodsTotal, - numberOfPodsSleeped, - new Decimal(0), - ), - [co2PerPod, numberOfPodsTotal, numberOfPodsSleeped], + () => + calculateCO2WeekConsumption( + co2PerPod, + numberOfPodsTotal, + numberOfPodsSleeped, + new Decimal(0) + ), + [co2PerPod, numberOfPodsTotal, numberOfPodsSleeped] + ); + const percentCO2Saved = React.useMemo( + () => + Math.round( + (Math.abs(resultWithoutKubeGreen - resultWithKubeGreen) / + resultWithoutKubeGreen) * + 1000 + ) / 10, + [resultWithoutKubeGreen, resultWithKubeGreen] ); return ( -
+

CO2 Calculator

@@ -62,24 +77,12 @@ export default function ConsumptionCalculator() {
Total (Kg CO2eq/week)
+ {percentCO2Saved}% CO2 saved with kube-green +
+
+
without kube-green: {resultWithoutKubeGreen.toString()}
- without kube-green: - {' '} - {resultWithoutKubeGreen.toString()} -
-
- - with kube-green: - {' '} - {resultWithKubeGreen.toString()} - -
-
- - Difference: - {' '} - {resultWithKubeGreen.minus(resultWithoutKubeGreen).toString()} - + with kube-green: {resultWithKubeGreen.toString()}
@@ -92,7 +95,7 @@ function calculateCO2WeekConsumption( co2PerPod: Decimal, totalNumberOfPods: Decimal, numberOfPodsSleeped: Decimal, - sleepHour: Decimal, + sleepHour: Decimal ): Decimal { const co2PerDayPerPod = co2PerPod.dividedBy(365).dividedBy(24); const co2WithKubeGreen = co2PerDayPerPod @@ -112,9 +115,7 @@ interface InputCalculator { function CalcInput({ label, value, onInputChange }: InputCalculator) { return (
-
- {label} -
+
{label}
Date: Tue, 16 Jan 2024 18:09:55 +0100 Subject: [PATCH 2/3] fix: typo and improve configuration section MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Arsène Fougerouse --- docs/configuration.md | 28 ++++++++++++++++++---------- docs/getting-started.mdx | 2 +- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 52a59f9..d29f6f9 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -9,16 +9,24 @@ An example of CRD is accessible [at this link](https://github.com/kube-green/kub The SleepInfo spec contains: -* **weekdays**: day of the week. `*` is every day, `1` is monday, `1-5` is from monday to friday -* **sleepAt**: time in hours and minutes (HH:mm) when namespace will go to sleep. Valid values are, for example, 19:00or `*:*` for every minute and every hour. Resources sleep will be deployments (setting replicas value to 0) and, if `suspendCronjobs` option is set to true, cron jobs will be suspended. -* **wakeUpAt** (*optional*): time in hours and minutes (HH:mm) when namespace should be restored to the initial state (before sleep). Valid values are, for example, 19:00or `*:*` for every minute and every hour. If wake up value is not set, pod in namespace will not be restored. So, you will need to deploy the initial namespace configuration to restore it. -* **timeZone** (*optional*, default to *UTC*): time zone in IANA specification. For example for italian hour, set `Europe/Rome`. -* **suspendDeployments** (*optional*, default to *true*): if set to false, deployments will not be suspended. -* **suspendCronJobs** (*optional*, default to *false*): if set to true, cronjobs will be suspended. -* **excludeRef** (*optional*): an array of object containing the resource to exclude from sleep. It can specify exactly the name of the specified resource or match based from the labels. The possible formats are: - * **apiVersion**: version of the resource. Now it is supported *"apps/v1"*, *"batch/v1beta1"* and *"batch/v1"* - * **kind**: the kind of resource. Now it is supported *"Deployment"* and *"CronJob"* - * **name**: the name of the resource +* **weekdays** +Day of the week. `*` is every day, `1` is monday, `1-5` is from monday to friday +* **sleepAt** +Time in hours and minutes (HH:mm) when namespace will go to sleep. Valid values are, for example, `19:00` or `*:*` for every minute and every hour. +Resources sleep will be deployments (setting replicas value to 0) and, if `suspendCronjobs` option is set to true, cron jobs will be suspended. +* **wakeUpAt** (*optional*) +Time in hours and minutes (HH:mm) when namespace should be restored to the initial state (before sleep). Valid values are, for example, `19:00` or `*:*` for every minute and every hour. If wake up value is not set, pod in namespace will not be restored. So, you will need to deploy the initial namespace configuration to restore it. +* **timeZone** (*optional*, default to *UTC*) +Time zone in IANA specification. For example for italian hour, set `Europe/Rome`. +* **suspendDeployments** (*optional*, default to *true*) +If set to false, deployments will not be suspended during sleep mode.. +* **suspendCronJobs** (*optional*, default to *false*) +If set to true, cronjobs will be suspended during sleep mode.. +* **excludeRef** (*optional*) +An array of object containing the resource to exclude from sleep. It can specify exactly the name of the specified resource or match based from the labels. The possible formats are: + * **apiVersion**: Version of the resource. Now it is supported *"apps/v1"*, *"batch/v1beta1"* and *"batch/v1"* + * **kind**: The kind of resource. Now it is supported *"Deployment"* and *"CronJob"* + * **name**: The name of the resource or * **matchLabels**: an object of strings with the labels to identify a resources click [here](#exclude-reference) to see an example. diff --git a/docs/getting-started.mdx b/docs/getting-started.mdx index a64f04d..53a4e91 100644 --- a/docs/getting-started.mdx +++ b/docs/getting-started.mdx @@ -11,7 +11,7 @@ How many of your dev/preview pods stay on during weekends? Or at night? It's a w *kube-green* is a simple k8s addon that automatically shuts down (some of) your resources when you don't need them. How many CO2 produces yearly a pod? -By our assumption, it's about 11 Kg CO2eq per per year per pod ([here](./FAQ.mdx#how-many-co2-is-produced-by-pod) the calculation). +By our assumption, it's about 11 Kg CO2eq per year per pod ([here](./FAQ.mdx#how-many-co2-is-produced-by-pod) the calculation). Use this tool to calculate it: From 8b026885cc073d51f48aa75511564e4113ece797 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ars=C3=A8ne=20Fougerouse?= Date: Tue, 16 Jan 2024 18:13:32 +0100 Subject: [PATCH 3/3] fix(docs): switch difference to positive MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Arsène Fougerouse --- docs/real-usecase/first-usage.md | 12 ++++++------ docs/real-usecase/node-downscale.md | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/real-usecase/first-usage.md b/docs/real-usecase/first-usage.md index 7c9f254..211da29 100644 --- a/docs/real-usecase/first-usage.md +++ b/docs/real-usecase/first-usage.md @@ -53,12 +53,12 @@ In this table, a comparison between before and after the use of *kube-green*. | | Total | With kube-green | Difference | | --------------------- | ------ | ---------------- | ---------------- | -| Number of pods | 446 | 205 | -241 | -| Memory consumed [Gb] | 28 | 16 | -12 | -| CPU consumed [cpu] | 2 | 1.3 | -0.7 | -| Memory allocated [Gb] | 34 | 22 | -12 | -| CPU allocated [cpu] | 14 | 12 | -2 | -| CO2eq/week [kg] | 94 | 66 | **-28** | +| Number of pods | 446 | 205 | 241 | +| Memory consumed [Gb] | 28 | 16 | 12 | +| CPU consumed [cpu] | 2 | 1.3 | 0.7 | +| Memory allocated [Gb] | 34 | 22 | 12 | +| CPU allocated [cpu] | 14 | 12 | 2 | +| CO2eq/week [kg] | 94 | 66 | **28** | As show in the table, are saved 28 Kg of CO2eq per week for this cluster. So in a year (52 weeks), the CO2eq saved is **-1456** Kg CO2eq. diff --git a/docs/real-usecase/node-downscale.md b/docs/real-usecase/node-downscale.md index 216d0c5..44ca77a 100644 --- a/docs/real-usecase/node-downscale.md +++ b/docs/real-usecase/node-downscale.md @@ -57,12 +57,12 @@ In this table, a comparison between before and after the use of *kube-green*. | | Total | With kube-green | Difference | | --------------------- | ------ | ---------------- | ---------------- | -| Number of pods | 1050 | 450 | -600 | -| Memory consumed [Gb] | 54 | 21 | -33 | -| CPU consumed [cpu] | 4.5 | 1 | -3.5 | -| Memory allocated [Gb] | 75 | 30 | -45 | -| CPU allocated [cpu] | 40 | 15 | -25 | -| CO2eq/week [kg] | 222 | 139 | **-83** | +| Number of pods | 1050 | 450 | 600 | +| Memory consumed [Gb] | 54 | 21 | 33 | +| CPU consumed [cpu] | 4.5 | 1 | 3.5 | +| Memory allocated [Gb] | 75 | 30 | 45 | +| CPU allocated [cpu] | 40 | 15 | 25 | +| CO2eq/week [kg] | 222 | 139 | **83** | As show in the table, are saved 83 Kg of CO2eq per week for this cluster. So in a year (52 weeks), the CO2eq saved is **-4316** Kg CO2eq.