UNPKG

@puls-atlas/cli

Version:

The Puls Atlas CLI tool for managing Atlas projects

137 lines 6.25 kB
import { normalizeOptionalString } from '../../../../utils/value.js'; export const AIRBYTE_SERVICE_MODULE_RELEASE_TAG = 'v0.1.0'; export const AIRBYTE_SERVICE_DEFAULT_MODULE_SOURCE = `git::https://github.com/limebooth/atlas-terraform-modules.git//airbyte/gke?ref=${AIRBYTE_SERVICE_MODULE_RELEASE_TAG}`; export const AIRBYTE_SERVICE_DEFAULT_ROOT_DIR = 'services/terraform/airbyte'; export const AIRBYTE_SERVICE_TEMPLATE_ROOT_DIRECTORIES = ['templates/service-airbyte-root', 'templates/search-workload-airbyte-root']; export const AIRBYTE_SERVICE_SECRET_KEYS = { adminPassword: 'instance-admin-password', databasePassword: 'postgresql-password' }; export const resolveAirbyteServiceManagedResourceNames = (serviceConfig = {}) => { const releaseName = normalizeOptionalString(serviceConfig.releaseName) ?? 'airbyte'; return { configSecretName: normalizeOptionalString(serviceConfig.configSecretName) ?? 'airbyte-config-secrets', globalAddressName: normalizeOptionalString(serviceConfig.globalAddressName) ?? `${releaseName}-airbyte-ip`, managedCertificateName: normalizeOptionalString(serviceConfig.managedCertificateName) ?? `${releaseName}-airbyte-cert`, namespace: normalizeOptionalString(serviceConfig.namespace) ?? 'airbyte', releaseName, roleBindingName: `${normalizeOptionalString(serviceConfig.serviceAccountName) ?? 'airbyte-admin'}-role-binding`, roleName: `${normalizeOptionalString(serviceConfig.serviceAccountName) ?? 'airbyte-admin'}-role`, serviceAccountName: normalizeOptionalString(serviceConfig.serviceAccountName) ?? 'airbyte-admin' }; }; const createAirbyteServiceResourcesPayload = resourcesConfig => { if (!resourcesConfig || typeof resourcesConfig !== 'object') { return null; } const payload = { ...(resourcesConfig.limits ? { limits: resourcesConfig.limits } : {}), ...(resourcesConfig.requests ? { requests: resourcesConfig.requests } : {}) }; return Object.keys(payload).length > 0 ? payload : null; }; const createAirbyteServiceBootloaderPayload = bootloaderConfig => { if (!bootloaderConfig || typeof bootloaderConfig !== 'object') { return null; } const resources = createAirbyteServiceResourcesPayload(bootloaderConfig.resources); const payload = { ...(bootloaderConfig.nodeSelector ? { node_selector: bootloaderConfig.nodeSelector } : {}), ...(Array.isArray(bootloaderConfig.tolerations) ? { tolerations: bootloaderConfig.tolerations } : {}), ...(resources ? { resources } : {}) }; return Object.keys(payload).length > 0 ? payload : null; }; const createAirbyteServiceBigQueryAccessPayload = bigQueryAccessConfig => { if (!bigQueryAccessConfig || typeof bigQueryAccessConfig !== 'object') { return null; } const payload = { ...(bigQueryAccessConfig.enabled === true ? { enabled: true } : {}), ...(normalizeOptionalString(bigQueryAccessConfig.projectId) ? { project_id: normalizeOptionalString(bigQueryAccessConfig.projectId) } : {}) }; return Object.keys(payload).length > 0 ? payload : null; }; const createAirbyteServiceExistingCredentialsPayload = runtimeInputs => { const payload = { ...(normalizeOptionalString(runtimeInputs?.adminPassword) ? { admin_password: normalizeOptionalString(runtimeInputs.adminPassword) } : {}), ...(normalizeOptionalString(runtimeInputs?.databasePassword) ? { database_password: normalizeOptionalString(runtimeInputs.databasePassword) } : {}) }; return Object.keys(payload).length > 0 ? payload : null; }; const createAirbyteServiceKubernetesPayload = terraformConnection => { if (!terraformConnection?.clusterEndpoint || !terraformConnection?.clusterCaCertificate) { return null; } return { cluster_ca_certificate: terraformConnection.clusterCaCertificate, host: terraformConnection.clusterEndpoint.startsWith('http') ? terraformConnection.clusterEndpoint : `https://${terraformConnection.clusterEndpoint}` }; }; export const createAirbyteServiceTerraformPayload = (context, serviceConfig, dependencies = {}) => { const bigQueryAccess = createAirbyteServiceBigQueryAccessPayload(serviceConfig.bigqueryAccess); const bootloader = createAirbyteServiceBootloaderPayload(serviceConfig.bootloader); const existingCredentials = createAirbyteServiceExistingCredentialsPayload(dependencies.runtimeInputs); const kubernetes = createAirbyteServiceKubernetesPayload(dependencies.terraformConnection); return { airbyte: { admin_email: serviceConfig.adminEmail, ...(existingCredentials ? existingCredentials : {}), airbyte_version: serviceConfig.airbyteVersion, ...(Number.isInteger(serviceConfig.backendTimeoutSec) ? { backend_timeout_sec: serviceConfig.backendTimeoutSec } : {}), ...(bigQueryAccess ? { bigquery_access: bigQueryAccess } : {}), ...(bootloader ? { bootloader } : {}), chart_name: serviceConfig.chartName, chart_repository: serviceConfig.chartRepository, chart_version: serviceConfig.chartVersion, config_secret_name: serviceConfig.configSecretName, create_namespace: serviceConfig.createNamespace, database_storage_size: serviceConfig.databaseStorageSize, gcp_service_account_email: serviceConfig.gcpServiceAccountEmail, global_address_name: serviceConfig.globalAddressName, host: serviceConfig.host, ingress_annotations: serviceConfig.ingressAnnotations, ingress_class_name: serviceConfig.ingressClassName, managed_certificate_name: serviceConfig.managedCertificateName, minio_storage_size: serviceConfig.minioStorageSize, name: serviceConfig.releaseName, namespace: serviceConfig.namespace, node_selector: serviceConfig.nodeSelector, service_account_name: serviceConfig.serviceAccountName, tolerations: serviceConfig.tolerations }, contract_version: dependencies.contractVersion ?? 1, environment: context.environment ?? null, ...(kubernetes ? { kubernetes } : {}), project_id: context.projectId, resource_labels: dependencies.resourceLabels ?? {}, service: 'airbyte', workload: 'airbyte' }; };