Skip to content

Commit 1d1938e

Browse files
Clarify Readme (#126)
* Add to readme about referencing objects outside of the core API * Update usage section * Apply suggestions from code review Co-authored-by: pablochacin <pablochacin@gmail.com>
1 parent da29c66 commit 1d1938e

File tree

1 file changed

+63
-3
lines changed

1 file changed

+63
-3
lines changed

README.md

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,26 @@ Using the `k6` binary with `xk6-kubernetes`, run the k6 test as usual:
4444
```
4545
# Usage
4646

47-
The API assumes a `kubeconfig` configuration is available at any of the following default locations:
48-
* at the location pointed by the `KUBECONFIG` environment variable
49-
* at `$HOME/.kube`
47+
By default, the API assumes a `kubeconfig` configuration is available at `$HOME/.kube`.
5048

49+
Alternatively, you can pass in the following options as a javascript Object to the Kubernetes constructor to configure access to the Kubernetes API server:
50+
51+
| Option | Value | Description |
52+
| -- | --| ---- |
53+
| config_path | /path/to/kubeconfig | Kubeconfig file location. You can also set this to __ENV.KUBECONFIG to use the location pointed by the `KUBECONFIG` environment variable |
54+
| server | <SERVER_HOST> | Kubernetes API server URL |
55+
| token | <TOKEN> | Bearer Token for authenticating to the Kubernetes API server |
56+
57+
```javascript
58+
59+
import { Kubernetes } from 'k6/x/kubernetes';
60+
61+
export default function () {
62+
const k = new Kubernetes({
63+
config_map: '/path/to/kubeconfig',
64+
});
65+
}
66+
```
5167
5268
# APIs
5369
@@ -141,6 +157,50 @@ export default function () {
141157
}
142158
```
143159
160+
#### Interacting with objects created by CRDs
161+
162+
For objects outside of the core API, use the fully-qualified resource name.
163+
164+
```javascript
165+
166+
import { Kubernetes } from 'k6/x/kubernetes';
167+
168+
const manifest = `
169+
apiVersion: networking.k8s.io/v1
170+
kind: Ingress
171+
metadata:
172+
name: yaml-ingress
173+
namespace: default
174+
spec:
175+
ingressClassName: nginx
176+
rules:
177+
- http:
178+
paths:
179+
- path: /my-service-path
180+
pathType: Prefix
181+
backend:
182+
service:
183+
name: my-service
184+
port:
185+
number: 80
186+
`
187+
188+
export default function () {
189+
const kubernetes = new Kubernetes();
190+
191+
kubernetes.apply(manifest);
192+
193+
const ingresses = kubernetes.list("Ingress.networking.k8s.io", "default")
194+
195+
console.log(`${ingresses.length} Ingress found:`);
196+
ingresses.map(function(ingress) {
197+
console.log(` ${ingress.metadata.name}`)
198+
});
199+
}
200+
201+
202+
```
203+
144204
## Helpers
145205
146206
The `xk6-kubernetes` extension offers helpers to facilitate common tasks when setting up a tests. All helper functions work in a namespace to facilitate the development of tests segregated by namespace. The helpers are accessed using the following method:

0 commit comments

Comments
 (0)