diff --git a/package.json b/package.json index c21b6c7..519efe8 100644 --- a/package.json +++ b/package.json @@ -21,26 +21,26 @@ "dependencies": { "bytes-iec": "^3.1.0", "got": "^9.6.0", - "roarr": "^2.13.2" + "roarr": "^2.14.6" }, "description": "Retrieves & observes Kubernetes Pod resource (CPU, memory) utilisation.", "devDependencies": { - "@babel/cli": "^7.4.4", - "@babel/core": "^7.4.5", - "@babel/node": "^7.4.5", - "@babel/plugin-transform-flow-strip-types": "^7.4.4", - "@babel/preset-env": "^7.4.5", - "@babel/register": "^7.4.4", - "ava": "^2.1.0", - "babel-plugin-istanbul": "^5.1.4", - "coveralls": "^3.0.4", - "delay": "^4.2.0", - "eslint": "^5.16.0", - "eslint-config-canonical": "^17.1.0", - "flow-bin": "^0.100.0", - "flow-copy-source": "^2.0.6", + "@babel/cli": "^7.7.5", + "@babel/core": "^7.7.5", + "@babel/node": "^7.7.4", + "@babel/plugin-transform-flow-strip-types": "^7.7.4", + "@babel/preset-env": "^7.7.6", + "@babel/register": "^7.7.4", + "ava": "^2.4.0", + "babel-plugin-istanbul": "^5.2.0", + "coveralls": "^3.0.9", + "delay": "^4.3.0", + "eslint": "^6.7.2", + "eslint-config-canonical": "^18.1.0", + "flow-bin": "^0.113.0", + "flow-copy-source": "^2.0.9", "nyc": "^14.1.1", - "semantic-release": "^15.13.12" + "semantic-release": "^15.13.31" }, "engines": { "node": ">6" diff --git a/src/Logger.js b/src/Logger.js index dbcb605..0646f54 100644 --- a/src/Logger.js +++ b/src/Logger.js @@ -3,5 +3,5 @@ import Roarr from 'roarr'; export default Roarr.child({ - package: 'preoom' + package: 'preoom', }); diff --git a/src/factories/createHttpClient.js b/src/factories/createHttpClient.js index 37a6ed3..7010619 100644 --- a/src/factories/createHttpClient.js +++ b/src/factories/createHttpClient.js @@ -2,7 +2,7 @@ import got from 'got'; import type { - HttpClientType + HttpClientType, } from '../types'; export default (certificateAuthority: string, serviceAccountToken: string): HttpClientType => { @@ -10,14 +10,14 @@ export default (certificateAuthority: string, serviceAccountToken: string): Http const response = await got(url, { agent: false, ca: [ - certificateAuthority + certificateAuthority, ], headers: { - Authorization: 'Bearer ' + serviceAccountToken + Authorization: 'Bearer ' + serviceAccountToken, }, json: true, rejectUnauthorized: true, - requestCert: true + requestCert: true, }); return response.body; diff --git a/src/factories/createResourceObserver.js b/src/factories/createResourceObserver.js index 1cb64c3..b292d18 100644 --- a/src/factories/createResourceObserver.js +++ b/src/factories/createResourceObserver.js @@ -3,39 +3,39 @@ import { getCredentials, getPodResourceSpecification, - getPodResourceUsage as getUnboundPodResourceUsage + getPodResourceUsage as getUnboundPodResourceUsage, } from '../services'; import Logger from '../Logger'; import type { - IntervalCallbackType + IntervalCallbackType, } from '../types'; import createHttpClient from './createHttpClient'; const log = Logger.child({ - namespace: 'createResourceObserver' + namespace: 'createResourceObserver', }); const createContext = async () => { const credentials = await getCredentials(); const httpClient = await createHttpClient( credentials.serviceCertificateAuthority, - credentials.serviceAccountToken + credentials.serviceAccountToken, ); const podResourceSpecification = await getPodResourceSpecification( httpClient, credentials.serviceUrl, credentials.podNamespace, - credentials.podName + credentials.podName, ); log.debug({ - podResourceSpecification + podResourceSpecification, }, 'pod resource specification'); return { credentials, httpClient, - podResourceSpecification + podResourceSpecification, }; }; @@ -49,7 +49,7 @@ export default () => { context.httpClient, context.credentials.serviceUrl, context.credentials.podNamespace, - context.credentials.podName + context.credentials.podName, ); return podResourceUsage; @@ -73,7 +73,7 @@ export default () => { log.debug({ podResourceSpecification, - podResourceUsage + podResourceUsage, }, 'observed resource usage'); // eslint-disable-next-line callback-return @@ -92,6 +92,6 @@ export default () => { return () => { clearTimeout(timeout); }; - } + }, }; }; diff --git a/src/index.js b/src/index.js index d52c324..f9a1183 100644 --- a/src/index.js +++ b/src/index.js @@ -1,8 +1,8 @@ // @flow export { - createResourceObserver + createResourceObserver, } from './factories'; export { - isKubernetesCredentialsPresent + isKubernetesCredentialsPresent, } from './utilities'; diff --git a/src/services/getCredentials.js b/src/services/getCredentials.js index 1144416..02e8da3 100644 --- a/src/services/getCredentials.js +++ b/src/services/getCredentials.js @@ -3,7 +3,7 @@ /* eslint-disable no-process-env */ import { - read + read, } from '../utilities'; type CredentialsType = {| @@ -11,7 +11,7 @@ type CredentialsType = {| +podNamespace: string, +serviceAccountToken: string, +serviceCertificateAuthority: string, - +serviceUrl: string + +serviceUrl: string, |}; export default (): CredentialsType => { @@ -54,6 +54,6 @@ export default (): CredentialsType => { podNamespace, serviceAccountToken, serviceCertificateAuthority, - serviceUrl + serviceUrl, }; }; diff --git a/src/services/getPodResourceSpecification.js b/src/services/getPodResourceSpecification.js index 391b127..4226562 100644 --- a/src/services/getPodResourceSpecification.js +++ b/src/services/getPodResourceSpecification.js @@ -2,11 +2,11 @@ import { parseBytes, - parseCpu + parseCpu, } from '../utilities'; import type { PodResourceSpecificationType, - HttpClientType + HttpClientType, } from '../types'; export default async (httpClient: HttpClientType, serviceUrl: string, podNamespace: string, podName: string): Promise => { @@ -21,14 +21,14 @@ export default async (httpClient: HttpClientType, serviceUrl: string, podNamespa if (container.resources.limits) { limits = { cpu: container.resources.limits.cpu ? parseCpu(container.resources.limits.cpu) : null, - memory: container.resources.limits.memory ? parseBytes(container.resources.limits.memory) : null + memory: container.resources.limits.memory ? parseBytes(container.resources.limits.memory) : null, }; } if (container.resources.requests) { requests = { cpu: container.resources.requests.cpu ? parseCpu(container.resources.requests.cpu) : null, - memory: container.resources.requests.memory ? parseBytes(container.resources.requests.memory) : null + memory: container.resources.requests.memory ? parseBytes(container.resources.requests.memory) : null, }; } @@ -36,13 +36,13 @@ export default async (httpClient: HttpClientType, serviceUrl: string, podNamespa name: container.name, resources: { limits, - requests - } + requests, + }, }); } return { containers, - name: podName + name: podName, }; }; diff --git a/src/services/getPodResourceUsage.js b/src/services/getPodResourceUsage.js index 85a5e05..10b33ab 100644 --- a/src/services/getPodResourceUsage.js +++ b/src/services/getPodResourceUsage.js @@ -2,11 +2,11 @@ import { parseBytes, - parseCpu + parseCpu, } from '../utilities'; import type { PodResourceUsageType, - HttpClientType + HttpClientType, } from '../types'; export default async (httpClient: HttpClientType, serviceUrl: string, podNamespace: string, podName: string): Promise => { @@ -19,13 +19,13 @@ export default async (httpClient: HttpClientType, serviceUrl: string, podNamespa name: container.name, usage: { cpu: parseCpu(container.usage.cpu), - memory: parseBytes(container.usage.memory) - } + memory: parseBytes(container.usage.memory), + }, }); } return { containers, - name: podName + name: podName, }; }; diff --git a/src/types.js b/src/types.js index 816918a..8480522 100644 --- a/src/types.js +++ b/src/types.js @@ -9,31 +9,31 @@ type ContainerResourceUsageType = {| +name: string, +usage: {| +cpu: number, - +memory: number - |} + +memory: number, + |}, |}; export type PodResourceUsageType = {| +name: string, - +containers: $ReadOnlyArray + +containers: $ReadOnlyArray, |}; type ResourceType = {| +cpu: number | null, - +memory: number | null + +memory: number | null, |}; type ContainerResourceSpecificationType = {| +name: string, +resources: {| +limits: ResourceType | null, - +requests: ResourceType | null - |} + +requests: ResourceType | null, + |}, |}; export type PodResourceSpecificationType = {| +containers: $ReadOnlyArray, - +name: string + +name: string, |}; export type IntervalCallbackType = (podResourceSpecification: PodResourceSpecificationType, podResourceUsage: PodResourceUsageType) => void; diff --git a/src/utilities/parseBytes.js b/src/utilities/parseBytes.js index 3385c84..b548303 100644 --- a/src/utilities/parseBytes.js +++ b/src/utilities/parseBytes.js @@ -1,7 +1,7 @@ // @flow import { - parse as parseBytes + parse as parseBytes, } from 'bytes-iec'; export default (iecBytes: string) => {