Skip to content

Commit

Permalink
Merge pull request #95 from grafana/paul/remove-deprecations
Browse files Browse the repository at this point in the history
Removed deprecated APIs
  • Loading branch information
javaducky authored Apr 24, 2023
2 parents 1955c37 + cfaa46b commit cf95003
Show file tree
Hide file tree
Showing 27 changed files with 43 additions and 5,628 deletions.
319 changes: 1 addition & 318 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ The methods above return an object that implements the following helper function
### Examples
### Creating a pod in a random namespace and wait until it is running
### Creating a pod and wait until it is running
```javascript
import { Kubernetes } from 'k6/x/kubernetes';
Expand Down Expand Up @@ -218,320 +218,3 @@ export default function () {
}
}
```
## Resource kind helpers
This API offers a helper for each kind of Kubernetes resources supported (Pods, Deployments, Secrets, et cetera). For each one, an interface for creating, getting, listing and deleting objects is offered.
>⚠️ This interface is deprecated and will be removed soon
> -
Migrate to the usage of the generic resources API.
</br>
### (Deprecated) Create a client: `new Kubernetes(config)`
Creates a Kubernetes client to interact with the Kubernetes cluster.
| Config options | Type | Description | Default |
| ------------ | ------ | ---------------------------------------- | ------ |
| config_path | String | The path to the kubeconfig file | ~/.kube/config |
```javascript
import { Kubernetes } from 'k6/x/kubernetes';
export default function () {
const kubernetesClient = new Kubernetes({
// config_path: "/path/to/kube/config"
})
}
```
### (Deprecated) `Client.config_maps`
| Method | Description |
| ------------ | ------ |
| apply | creates the Kubernetes resource given a YAML configuration |
| create | creates the Kubernetes resource given an object configuration |
| delete | removes the named ConfigMap |
| get | returns the named ConfigMaps |
| list | returns a collection of ConfigMaps |
```javascript
import { Kubernetes } from 'k6/x/kubernetes';
export default function () {
const kubernetesClient = new Kubernetes({});
const nameSpace = "default";
const name = "config-map-name";
kubernetesClient.config_maps.apply(getConfigMapYaml(name), nameSpace);
}
```
### (Deprecated) `Client.deployments`
| Method | Description |
| ------------ | ------ |
| apply | creates the Kubernetes resource given a YAML configuration |
| create | creates the Kubernetes resource given an object configuration |
| delete | removes the named Deployment |
| get | returns the named Deployment |
| list | returns a collection of Deployments |
```javascript
import { Kubernetes } from 'k6/x/kubernetes';
export default function () {
const kubernetesClient = new Kubernetes({});
const nameSpace = "default";
const name = "deployment-name";
const app = 'app-label';
kubernetesClient.deployments.apply(getDeploymentYaml(name, app), nameSpace);
}
```
### (Deprecated) `Client.ingresses`
| Method | Description |
| ------------ | ------ |
| apply | creates the Kubernetes resource given a YAML configuration |
| create | creates the Kubernetes resource given an object configuration |
| delete | removes the named Ingress |
| get | returns the named Ingress |
| list | returns a collection of Ingresses |
```javascript
import { Kubernetes } from 'k6/x/kubernetes';
export default function () {
const kubernetesClient = new Kubernetes({});
const nameSpace = "default";
const name = "deployment-name";
const url = 'ingress-url.com';
kubernetesClient.ingresses.apply(getIngressYaml(name, url), nameSpace);
}
```
### (Deprecated) `Client.jobs`
| Method | Description |
| ------------ | ------ |
| apply | creates the Kubernetes resource given a YAML configuration |
| create | creates the Kubernetes resource given an object configuration |
| delete | removes the named Job |
| get | returns the named Jobs |
| list | returns a collection of Jobs |
| wait | wait for all Jobs to complete |
```javascript
import { Kubernetes } from 'k6/x/kubernetes';
export default function () {
const kubernetesClient = new Kubernetes({});
const namespace = "default"
const jobName = "new-job"
const image = "perl"
const command = ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
kubernetesClient.jobs.create({
namespace: namespace,
name: jobName,
image: image,
command: command
})
const completed = kubernetesClient.jobs.wait({
namespace: namespace,
name: jobName,
timeout: "30s"
})
const jobStatus = completed? "completed": "not completed"
}
```
### (Deprecated) `Client.namespaces`
| Method | Description |
| ------------ | ------ |
| apply | creates the Kubernetes resource given a YAML configuration |
| create | creates the Kubernetes resource given an object configuration |
| delete | removes the named Namespaces |
| get | returns the named Namespace |
| list | returns a collection of Namespaces |
```javascript
import { Kubernetes } from 'k6/x/kubernetes';
export default function () {
const kubernetesClient = new Kubernetes({});
const name = "namespace-name";
kubernetesClient.namespaces.apply(getNamespaceYaml(name));
}
```
### (Deprecated) `Client.nodes`
| Method | Description |
| ------------ | ------ |
| list | returns a collection of Nodes comprising the cluster |
```javascript
import { Kubernetes } from 'k6/x/kubernetes';
export default function () {
const kubernetesClient = new Kubernetes({});
const nodes = kubernetesClient.nodes.list()
}
```
### (Deprecated) `Client.persistent_volumes`
| Method | Description |
| ------------ | ------ |
| apply | creates the Kubernetes resource given a YAML configuration |
| create | creates the Kubernetes resource given an object configuration |
| delete | removes the named persistent volume |
| get | returns the named persistent volume instance |
| list | returns a collection of persistent volumens |
```javascript
import { Kubernetes } from 'k6/x/kubernetes';
export default function () {
const kubernetesClient = new Kubernetes({});
const name = "example-pv";
kubernetesClient.persistent_volumes.apply(getPVYaml(name, "1Gi", "local-storage"));
}
```
### (Deprecated) `Client.persistent_volumes_claims`
| Method | Description |
| ------------ | ------ |
| apply | creates the Kubernetes resource given a YAML configuration |
| create | creates the Kubernetes resource given an object configuration |
| delete | removes the named persistent volume claim |
| get | returns the named persistent volume claim |
| list | returns a collection of persistent volumen claims |
```javascript
import { Kubernetes } from 'k6/x/kubernetes';
export default function () {
const kubernetesClient = new Kubernetes({});
const name = "example-pvc";
const nameSpace = "default";
kubernetes.persistent_volume_claims.apply(getPVCYaml(name, "1Gi", "nfs-csi"), nameSpace);
}
```
### (Deprecated) `Client.pods`
| Method | Description |
| ------------ | ------ |
| create | runs a pod |
| delete | removes the named Pod |
| get | returns the named Pod |
| list | returns a collection of Pods |
| wait | wait for the Pod to be in a given status |
| exec | executes a non-interactive command |
| addEphemeralContainer | adds an ephemeral container to a running pod |
```javascript
import { Kubernetes } from 'k6/x/kubernetes';
export default function () {
const kubernetesClient = new Kubernetes({});
const namespace = "default"
const podName = "new-pod"
const image = "busybox"
const command = ["sh", "-c", "sleep 5"]
kubernetesClient.pods.create({
namespace: namespace,
name: podName,
image: image,
command: command
});
const options = {
namespace: namespace,
name: podName,
status: "Succeeded",
timeout: "10s"
}
if (kubernetesClient.pods.wait(options)) {
console.log(podName + " pod completed successfully")
} else {
throw podName + " is not completed"
}
}
```
### (Deprecated) `Client.secrets`
| Method | Description |
| ------------ | ------ |
| apply | creates the Kubernetes resource given a YAML configuration |
| create | creates the Kubernetes resource given an object configuration |
| delete | removes the named secret |
| get | returns the named secret |
| list | returns a collection of secrets |
```javascript
import { Kubernetes } from 'k6/x/kubernetes';
export default function () {
const kubernetesClient = new Kubernetes({});
const secrets = kubernetesClient.secrets.list()
}
```
### (Deprecated) `Client.services`
| Method | Description |
| ------------ | ------ |
| apply | creates the Kubernetes resource given a YAML configuration |
| create | creates the Kubernetes resource given an object configuration |
| delete | removes the named service |
| get | returns the named service |
| list | returns a collection of services |
```javascript
import { Kubernetes } from 'k6/x/kubernetes';
export default function () {
const kubernetesClient = new Kubernetes({});
const svcs = kubernetesClient.services.list()
}
```
## If things go wrong
### Are you using the custom binary?
An easy mistake--which happens often--is to forget that `xk6` is generating a new executable. You may be accustomed to simply running `k6` from the command-line which probably isn't your new build. Make sure to use `./k6` after building your extended version otherwise you can expect to see an error similar to:
```bash
ERRO[0000] The moduleSpecifier "k8s-test-script.js" couldn't be found on local disk. Make sure that you've specified the right path to the file. If you're running k6 using the Docker image make sure you have mounted the local directory (-v /local/path/:/inside/docker/path) containing your script and modules so that they're accessible by k6 from inside of the container, see https://k6.io/docs/using-k6/modules#using-local-modules-with-docker. Additionally it was tried to be loaded as remote module by prepending "https://" to it, which also didn't work. Remote resolution error: "Get "https://k8s-test-script.js": dial tcp: lookup k8s-test-script.js: no such host"
```
Loading

0 comments on commit cf95003

Please sign in to comment.