Skip to content

Commit

Permalink
Merge pull request #60 from GridexX/main
Browse files Browse the repository at this point in the history
Improve severall sections
  • Loading branch information
davidebianchi authored Jan 20, 2024
2 parents a3cc264 + 8b02688 commit 9c3f5df
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 65 deletions.
28 changes: 18 additions & 10 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
12 changes: 6 additions & 6 deletions docs/real-usecase/first-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions docs/real-usecase/node-downscale.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
85 changes: 43 additions & 42 deletions src/components/ConsumptionCalculator.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,51 @@
import React from 'react';
import Decimal from 'decimal.js-light';
import React from "react";

Check failure on line 1 in src/components/ConsumptionCalculator.tsx

View workflow job for this annotation

GitHub Actions / docs-build / Build docs (1.19, lts/*)

Strings must use singlequote
import Decimal from "decimal.js-light";

Check failure on line 2 in src/components/ConsumptionCalculator.tsx

View workflow job for this annotation

GitHub Actions / docs-build / Build docs (1.19, lts/*)

Strings must use singlequote

import clsx from 'clsx';
import styles from './ConsumptionCalculator.module.css';
import clsx from "clsx";

Check failure on line 4 in src/components/ConsumptionCalculator.tsx

View workflow job for this annotation

GitHub Actions / docs-build / Build docs (1.19, lts/*)

Strings must use singlequote
import styles from "./ConsumptionCalculator.module.css";

Check failure on line 5 in src/components/ConsumptionCalculator.tsx

View workflow job for this annotation

GitHub Actions / docs-build / Build docs (1.19, lts/*)

Strings must use singlequote

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)

Check failure on line 11 in src/components/ConsumptionCalculator.tsx

View workflow job for this annotation

GitHub Actions / docs-build / Build docs (1.19, lts/*)

Missing trailing comma
);
const [numberOfHourSleepInWeek, setNumberOfHourSleepInWeek] = React.useState(
new Decimal(128)

Check failure on line 14 in src/components/ConsumptionCalculator.tsx

View workflow job for this annotation

GitHub Actions / docs-build / Build docs (1.19, lts/*)

Missing trailing comma
);

const resultWithKubeGreen = React.useMemo(
() => calculateCO2WeekConsumption(
co2PerPod,
numberOfPodsTotal,
numberOfPodsSleeped,
numberOfHourSleepInWeek,
),
[co2PerPod, numberOfPodsTotal, numberOfPodsSleeped, numberOfHourSleepInWeek],
() =>
calculateCO2WeekConsumption(

Check failure on line 19 in src/components/ConsumptionCalculator.tsx

View workflow job for this annotation

GitHub Actions / docs-build / Build docs (1.19, lts/*)

Expected no linebreak before this expression
co2PerPod,
numberOfPodsTotal,
numberOfPodsSleeped,
numberOfHourSleepInWeek

Check failure on line 23 in src/components/ConsumptionCalculator.tsx

View workflow job for this annotation

GitHub Actions / docs-build / Build docs (1.19, lts/*)

Missing trailing comma
),
[co2PerPod, numberOfPodsTotal, numberOfPodsSleeped, numberOfHourSleepInWeek]

Check failure on line 25 in src/components/ConsumptionCalculator.tsx

View workflow job for this annotation

GitHub Actions / docs-build / Build docs (1.19, lts/*)

Missing trailing comma
);
const resultWithoutKubeGreen = React.useMemo(
() => calculateCO2WeekConsumption(
co2PerPod,
numberOfPodsTotal,
numberOfPodsSleeped,
new Decimal(0),
),
[co2PerPod, numberOfPodsTotal, numberOfPodsSleeped],
() =>
calculateCO2WeekConsumption(

Check failure on line 29 in src/components/ConsumptionCalculator.tsx

View workflow job for this annotation

GitHub Actions / docs-build / Build docs (1.19, lts/*)

Expected no linebreak before this expression
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 (
<div className={clsx(styles.card, 'card')}>
<div className={clsx(styles.card, "card")}>
<div className="card__header">
<h2>CO2 Calculator</h2>
</div>
Expand Down Expand Up @@ -62,24 +77,12 @@ export default function ConsumptionCalculator() {
<div className={styles.subTitle}>Total (Kg CO2eq/week)</div>
</h3>
<div>
<b>{percentCO2Saved}% CO2 saved</b> with kube-green
</div>
<div>
<div>without kube-green: {resultWithoutKubeGreen.toString()}</div>
<div>
without kube-green:
{' '}
{resultWithoutKubeGreen.toString()}
</div>
<div>
<b>
with kube-green:
{' '}
{resultWithKubeGreen.toString()}
</b>
</div>
<div>
<b>
Difference:
{' '}
{resultWithKubeGreen.minus(resultWithoutKubeGreen).toString()}
</b>
<b>with kube-green: {resultWithKubeGreen.toString()}</b>
</div>
</div>
</div>
Expand All @@ -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
Expand All @@ -112,9 +115,7 @@ interface InputCalculator {
function CalcInput({ label, value, onInputChange }: InputCalculator) {
return (
<div className={styles.inputWrapper}>
<div>
{label}
</div>
<div>{label}</div>
<div>
<input
className={styles.inputCalc}
Expand Down

0 comments on commit 9c3f5df

Please sign in to comment.