-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add isKubernetesCredentialsPresent
- Loading branch information
Showing
7 changed files
with
155 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// @flow | ||
|
||
export {default as isKubernetesCredentialsPresent} from './isKubernetesCredentialsPresent'; | ||
export {default as parseBytes} from './parseBytes'; | ||
export {default as read} from './read'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// @flow | ||
|
||
/* eslint-disable no-process-env */ | ||
|
||
import read from './read'; | ||
|
||
export default () => { | ||
const kubernetesServiceHost = process.env.KUBERNETES_SERVICE_HOST || null; | ||
const kubernetesServicePort = process.env.KUBERNETES_PORT_443_TCP_PORT || null; | ||
const podName = process.env.HOSTNAME || null; | ||
|
||
if (!kubernetesServiceHost || !kubernetesServicePort || !podName) { | ||
return false; | ||
} | ||
|
||
const serviceAccountToken = read('/var/run/secrets/kubernetes.io/serviceaccount/token'); | ||
const serviceCertificateAuthority = read('/var/run/secrets/kubernetes.io/serviceaccount/ca.crt'); | ||
const podNamespace = read('/var/run/secrets/kubernetes.io/serviceaccount/namespace'); | ||
|
||
return serviceAccountToken && serviceCertificateAuthority && podNamespace; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// @flow | ||
|
||
import fs from 'fs'; | ||
|
||
export default (filePath: string): string | null => { | ||
try { | ||
return fs.readFileSync(filePath, 'utf8'); | ||
} catch (error) { | ||
return null; | ||
} | ||
}; |