-
Notifications
You must be signed in to change notification settings - Fork 20
/
persistentvolume_operations.js
97 lines (81 loc) · 2.87 KB
/
persistentvolume_operations.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { Kubernetes } from 'k6/x/kubernetes';
import { describe, expect } from 'https://jslib.k6.io/k6chaijs/4.3.4.3/index.js';
import { load, dump } from 'https://cdn.jsdelivr.net/npm/[email protected]/dist/js-yaml.mjs';
let json = {
apiVersion: "v1",
kind: "PersistentVolume",
metadata: {
name: "json-pv",
},
spec: {
storageClassName: "manual",
capacity: {
storage: "1Mi",
},
accessModes: [
"ReadWriteOnce"
],
hostPath: {
path: "/tmp/k3dvol",
},
}
}
let yaml = `
apiVersion: v1
kind: PersistentVolume
metadata:
name: yaml-pv
spec:
storageClassName: "manual"
capacity:
storage: 1Mi
accessModes:
- ReadWriteOnce
hostPath:
path: /tmp/k3dvol
`
export default function () {
const kubernetes = new Kubernetes();
describe('JSON-based resources', () => {
const name = json.metadata.name
let created
describe('Create our PersistentVolume using the JSON definition', () => {
created = kubernetes.create(json)
expect(created.metadata, 'new persistentvolume').to.have.property('uid')
})
describe('Retrieve our PersistentVolume by name', () => {
let fetched = kubernetes.get("PersistentVolume", name)
expect(created.metadata.uid, 'created and fetched uids').to.equal(fetched.metadata.uid)
})
describe('Update our PersistentVolume with a modified JSON definition', () => {
const newValue = "10Mi"
json.spec.capacity.storage = newValue
kubernetes.update(json)
let updated = kubernetes.get("PersistentVolume", name)
expect(updated.spec.capacity.storage, 'changed value').to.be.equal(newValue)
})
describe('Remove our PersistentVolume to cleanup', () => {
kubernetes.delete("PersistentVolume", name)
})
})
describe('YAML-based resources', () => {
let yamlObject = load(yaml)
const name = yamlObject.metadata.name
describe('Create our PersistentVolume using the YAML definition', () => {
kubernetes.apply(yaml)
let created = kubernetes.get("PersistentVolume", name)
expect(created.metadata, 'new persistentvolume').to.have.property('uid')
})
describe('Update our PersistentVolume with a modified YAML definition', () => {
const newValue = "10Mi"
yamlObject.spec.capacity.storage = newValue
let newYaml = dump(yamlObject)
kubernetes.apply(newYaml)
let updated = kubernetes.get("PersistentVolume", name)
expect(updated.spec.capacity.storage, 'changed value').to.be.equal(newValue)
})
describe('Remove our PersistentVolume to cleanup', () => {
kubernetes.delete("PersistentVolume", name)
})
})
}