|
| 1 | +'use strict' |
| 2 | + |
| 3 | +const fs = require('fs'); |
| 4 | +const parseArgs = require('minimist'); |
| 5 | +const demoType = parseArgs(process.argv.slice(2)); |
| 6 | + |
| 7 | +// Location of custom CA crt |
| 8 | +const ca = fs.readFileSync(__dirname + '/ca.crt'); |
| 9 | + |
| 10 | +// Unwise option to turn off all TLS security in NodeJS. NodeJS uses a predefined list of trusted CAs and ignores the system CA store. Workaround was to append CA/cert/keys in ApiClient modification. |
| 11 | +// process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; |
| 12 | +const kubernetes = require('./index'); |
| 13 | +// UnversionedPatch model file was not generated, so a stub was put in. |
| 14 | + |
| 15 | +const apiClient = new kubernetes.ApiClient(); |
| 16 | +apiClient.ca = ca; |
| 17 | +apiClient.basePath = 'https://192.168.99.100:8443'; |
| 18 | +// Authorization of personal minikube setup - not considered a security concern due to local nature - in actual use should be provided by user. |
| 19 | +apiClient.defaultHeaders = { |
| 20 | + "Authorization": "Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJkZWZhdWx0Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZWNyZXQubmFtZSI6ImRlZmF1bHQtdG9rZW4ta24wMHMiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGVmYXVsdCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6Ijk3MTBkNjc3LWRjNjctMTFlNi05NWMyLTA4MDAyNzY4YjNlYiIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDpkZWZhdWx0OmRlZmF1bHQifQ.RqeMeu3zxYqfGHpDV0vlVjG8EYgp_dG4Dr8dNc9zN-5J-tUOE_lBJ5VUWwh08GpN7jL3L66IZJ-zmJevVj7bd3OZBaGGTrEzgCrfuyrLIuPY-af8rZkElAtEaFdiT0m-z7JQqpUJ0yz9cZcOHiKN3vLR9zB7kVYcDWvMPwzzJsP65gPQptU1mRcx7w0wPtO8OmQXkrwrxoySwJpj7ug4Qv-QAIW9_Xa67qUUtKNaP1lgRIt9r4UL1fOrzS0fDNgBQClQ3CupkKRFQ4q7nvp6GkE-8HGzIg4tG65khfD2i750InZHGFZhLCTFmjiS-bmXx-MezEPb5rJ4rovMXcWj9w" |
| 21 | +}; |
| 22 | + |
| 23 | +// Core test |
| 24 | + |
| 25 | +const core = new kubernetes.CoreApi(apiClient); |
| 26 | +const coreApi = new kubernetes.CorevApi(apiClient); |
| 27 | +const extensions = new kubernetes.ExtensionsvbetaApi(apiClient); |
| 28 | +const version = new kubernetes.VersionApi(apiClient); |
| 29 | + |
| 30 | +// Versions |
| 31 | +if (demoType['v']) { |
| 32 | + core.getCoreAPIVersions(function(error, data, response) { |
| 33 | + console.log(error, data); |
| 34 | + }); |
| 35 | + |
| 36 | + version.getCodeVersion(function(error, data, response) { |
| 37 | + console.log(error, data); |
| 38 | + }); |
| 39 | +} |
| 40 | + |
| 41 | +// Test creation of namespace and deployment |
| 42 | +if (demoType['c']) { |
| 43 | + const testNs = "{\"kind\":\"Namespace\",\"apiVersion\":\"v1\",\"metadata\":{\"name\":\"client-test\",\"creationTimestamp\":null},\"spec\":{},\"status\":{}}\n"; |
| 44 | + coreApi.createCoreV1Namespace(testNs, {}, function(error, data, response) { |
| 45 | + console.log(error, data); |
| 46 | + }); |
| 47 | + |
| 48 | + |
| 49 | + const testDep = "{\"kind\":\"Deployment\",\"apiVersion\":\"extensions/v1beta1\",\"metadata\":{\"name\":\"hello-world\",\"creationTimestamp\":null,\"labels\":{\"run\":\"hello-world\"}},\"spec\":{\"replicas\":1,\"selector\":{\"matchLabels\":{\"run\":\"hello-world\"}},\"template\":{\"metadata\":{\"creationTimestamp\":null,\"labels\":{\"run\":\"hello-world\"}},\"spec\":{\"containers\":[{\"name\":\"hello-world\",\"image\":\"hello-world\",\"ports\":[{\"containerPort\":8080}],\"resources\":{}}]}},\"strategy\":{}},\"status\":{}}\n"; |
| 50 | + const deployment = kubernetes.V1beta1Deployment.constructFromObject(JSON.parse(testDep)); |
| 51 | + |
| 52 | + extensions.createExtensionsV1beta1NamespacedDeployment('default', JSON.stringify(deployment), {pretty: false}, function(error, data, response) { |
| 53 | + console.log(error, data); |
| 54 | + }); |
| 55 | + |
| 56 | +} |
| 57 | + |
| 58 | + |
| 59 | +// Read deployment |
| 60 | +if (demoType['r']) { |
| 61 | + extensions.listExtensionsV1beta1NamespacedDeployment('default', {pretty: false}, function(error, data, response) { |
| 62 | + console.log(error, data); |
| 63 | + }); |
| 64 | + |
| 65 | + extensions.readExtensionsV1beta1NamespacedDeployment('hello-world', 'default', {pretty: false}, function(error, data, response) { |
| 66 | + console.log(error, data); |
| 67 | + }); |
| 68 | +} |
| 69 | + |
| 70 | +// TEARDOWN |
| 71 | +if (demoType['d']) { |
| 72 | + const testDel = "{\"kind\":\"DeleteOptions\",\"apiVersion\":\"extensions/v1beta1\",\"orphanDependents\":false}\n"; |
| 73 | + const delopts = kubernetes.V1beta1Deployment.constructFromObject(JSON.parse(testDel)); |
| 74 | + extensions.deleteExtensionsV1beta1NamespacedDeployment('hello-world', 'default', JSON.stringify(delopts), {pretty: false}, function(error, data, response) { |
| 75 | + console.log(error, data); |
| 76 | + }); |
| 77 | + |
| 78 | + const delTestNs = "{\"kind\":\"DeleteOptions\",\"apiVersion\":\"v1\",\"metadata\":{\"name\":\"client-test\",\"deletionGracePeriodSeconds\":\"60\"},\"spec\":{},\"status\":{}}\n"; |
| 79 | + coreApi.deleteCoreV1Namespace('client-test', delTestNs, {}, function(error, data, response) { |
| 80 | + console.log(error, data); |
| 81 | + }); |
| 82 | +} |
0 commit comments