mirror of
https://github.com/tale/headplane.git
synced 2026-09-03 10:48:17 +00:00
feat(TALE-7): reimplement integration system
This commit is contained in:
+19
-39
@@ -1,28 +1,18 @@
|
||||
import docker from './docker'
|
||||
import kubernetes from './kubernetes'
|
||||
import proc from './proc'
|
||||
import dockerIntegration from './docker'
|
||||
import kubernetesIntegration from './kubernetes'
|
||||
import procIntegration from './proc'
|
||||
|
||||
export interface Integration {
|
||||
name: string
|
||||
preflight: () => Promise<boolean>
|
||||
sighup?: () => Promise<void>
|
||||
restart?: () => Promise<void>
|
||||
}
|
||||
export * from './integration'
|
||||
|
||||
// Because we previously supported the Docker integration by
|
||||
// checking for the HEADSCALE_CONTAINER variable, we need to
|
||||
// check for it here as well.
|
||||
//
|
||||
// This ensures that when people upgrade from older versions
|
||||
// of Headplane, they don't explicitly need to define the new
|
||||
// HEADSCALE_INTEGRATION variable that is needed to configure
|
||||
// an integration.
|
||||
export async function checkIntegration() {
|
||||
export function loadIntegration() {
|
||||
let integration = process.env.HEADSCALE_INTEGRATION
|
||||
?.trim()
|
||||
.toLowerCase()
|
||||
|
||||
// Old HEADSCALE_CONTAINER variable upgrade path
|
||||
// This ensures that when people upgrade from older versions of Headplane
|
||||
// they don't explicitly need to define the new HEADSCALE_INTEGRATION
|
||||
// variable that is needed to configure docker
|
||||
if (!integration && process.env.HEADSCALE_CONTAINER) {
|
||||
integration = 'docker'
|
||||
}
|
||||
@@ -32,32 +22,22 @@ export async function checkIntegration() {
|
||||
return
|
||||
}
|
||||
|
||||
let module: Integration | undefined
|
||||
try {
|
||||
module = getIntegration(integration)
|
||||
await module.preflight()
|
||||
} catch (error) {
|
||||
console.error('Failed to load integration', error)
|
||||
return
|
||||
}
|
||||
|
||||
return module
|
||||
}
|
||||
|
||||
function getIntegration(name: string) {
|
||||
switch (name) {
|
||||
switch (integration.toLowerCase().trim()) {
|
||||
case 'docker': {
|
||||
return docker
|
||||
return dockerIntegration
|
||||
}
|
||||
case 'proc': {
|
||||
return proc
|
||||
|
||||
case 'proc':
|
||||
case 'native':
|
||||
case 'linux': {
|
||||
return procIntegration
|
||||
}
|
||||
|
||||
case 'kubernetes':
|
||||
case 'k8s': {
|
||||
return kubernetes
|
||||
}
|
||||
default: {
|
||||
throw new Error(`Unknown integration: ${name}`)
|
||||
return kubernetesIntegration
|
||||
}
|
||||
}
|
||||
|
||||
console.error('Unknown integration:', integration)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user