Skip to content

Commit a19fdfd

Browse files
committed
Documentation
1 parent 9b1e4ab commit a19fdfd

File tree

1 file changed

+102
-1
lines changed

1 file changed

+102
-1
lines changed

README.md

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,102 @@
1-
# kubernetes-attributes
1+
# Contracts for Kubernetes related attributes
2+
3+
![Continuous Integration](https://github.com/mammatusphp/kubernetes-attributes/workflows/Continuous%20Integration/badge.svg)
4+
[![Latest Stable Version](https://poser.pugx.org/mammatus/kubernetes-attributes/v/stable.png)](https://packagist.org/packages/mammatus/kubernetes-attributes)
5+
[![Total Downloads](https://poser.pugx.org/mammatus/kubernetes-attributes/downloads.png)](https://packagist.org/packages/mammatus/kubernetes-attributes/stats)
6+
[![Type Coverage](https://shepherd.dev/github/mammatusphp/kubernetes-attributes/coverage.svg)](https://shepherd.dev/github/mammatusphp/kubernetes-attributes)
7+
[![License](https://poser.pugx.org/mammatus/kubernetes-attributes/license.png)](https://packagist.org/packages/mammatus/kubernetes-attributes)
8+
9+
# Install
10+
11+
To install via [Composer](http://getcomposer.org/), use the command below, it will automatically detect the latest version and bind it with `^`.
12+
13+
```
14+
composer require mammatus/kubernetes-attributes
15+
```
16+
17+
# Attributes
18+
19+
This package provides the following attributes:
20+
21+
## Resources
22+
23+
The `Resources` attribute is an addon for other attributes used in conjunction with the `SplitOut` attribute to
24+
configure the expected resources a split out operation can used. Both the `cpu` and `memory` arguments must provided
25+
with a non-negative value. The `cpu` argument works in full CPU cores. It translates everything into the string
26+
notation, so `1` becomes `1000m` and `13.37` becomes `13370m`. Same goes for the `memory` argument, it takes in
27+
GigaBytes and turns it into MegaBytes. `0.5` becomes `512Mi`.
28+
29+
## SplitOut
30+
31+
Mammatus is build with both big and small budgets in mind. By default every HTTP server, queue consumer, cronjob etc
32+
will run in a general all purpose pod. By using the `SplitOut` on that specific class will mark it to be a separate
33+
resource in Kubernetes. Cronjobs will become Kubernetes cronjob, the rest will become a deployment.
34+
35+
# Example
36+
37+
The following example is from one of the services that runs on my home cluster using both the `Resources` and
38+
`SplitOut` attributes:
39+
40+
```php
41+
<?php
42+
43+
declare(strict_types=1);
44+
45+
namespace WyriHaximus\Apps\WorldOfWarcraft\DataMiner\Images\BLP;
46+
47+
use Mammatus\Cron\Attributes\Cron;
48+
use Mammatus\Cron\Contracts\Action;
49+
use Mammatus\Kubernetes\Attributes\Resources;
50+
use Mammatus\Kubernetes\Attributes\SplitOut;
51+
use Psr\Log\LoggerInterface;
52+
53+
use function React\Async\await;
54+
use function substr;
55+
56+
#[SplitOut]
57+
#[Cron(
58+
'scan-images-blp-to-png',
59+
259200,
60+
'8 7 * * *',
61+
new Resources(
62+
cpu: 0.666,
63+
memory: 3,
64+
),
65+
)]
66+
final readonly class Scan implements Action
67+
{
68+
public function __construct(
69+
private LoggerInterface $logger,
70+
) {
71+
}
72+
73+
public function perform(): void
74+
{
75+
$this->logger->debug('Performing Cron Job');
76+
}
77+
}
78+
```
79+
80+
# License
81+
82+
The MIT License (MIT)
83+
84+
Copyright (c) 2024 Cees-Jan Kiewiet
85+
86+
Permission is hereby granted, free of charge, to any person obtaining a copy
87+
of this software and associated documentation files (the "Software"), to deal
88+
in the Software without restriction, including without limitation the rights
89+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
90+
copies of the Software, and to permit persons to whom the Software is
91+
furnished to do so, subject to the following conditions:
92+
93+
The above copyright notice and this permission notice shall be included in all
94+
copies or substantial portions of the Software.
95+
96+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
97+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
98+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
99+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
100+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
101+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
102+
SOFTWARE.

0 commit comments

Comments
 (0)