diff --git a/operator/src/backend-with-storage/handlers.ts b/operator/src/backend-with-storage/handlers.ts index 3ffc123..95b9a76 100644 --- a/operator/src/backend-with-storage/handlers.ts +++ b/operator/src/backend-with-storage/handlers.ts @@ -1,8 +1,7 @@ import { V1StatefulSet, V1PersistentVolumeClaim, PatchUtils, V1Container, V1EnvVar, V1Volume, V1VolumeMount } from '@kubernetes/client-node'; -import { getClients, Network, DependencyResource, ServicePlugin } from '@demeter-sdk/framework'; +import { getClients, Network } from '@demeter-sdk/framework'; import { API_VERSION, API_GROUP, PLURAL, SINGULAR, KIND } from './constants'; import { CustomResource, CustomResourceResponse, BackendWithStorage, StorageClass } from '@demeter-run/workloads-types'; -import { buildEnvVars, cardanoNodeDep, cleanDependencies, getDependenciesForNetwork } from '../shared/dependencies'; import { generateProjectSpec, getComputeDCUPerMin, @@ -16,7 +15,7 @@ import { workloadVolumes, } from '../shared'; import { checkConfigMapExistsOrCreate, configmap } from '../shared/configmap'; -import { buildSocatContainer, buildSocatContainerForPort } from '../shared/cardano-node-helper'; +import { buildSocatContainerForPort } from '../shared/cardano-node-helper'; import { buildPortEnvVars, getPortsForNetwork, portExists } from '../shared/ports'; import { ServiceInstanceWithStatusAndKind } from '../services'; @@ -56,15 +55,12 @@ export async function handleResource( } const network = getNetworkFromAnnotations(spec.annotations) as Network; - const deps = await getDependenciesForNetwork(project, network); const ports = await getPortsForNetwork(project, network); const portEnvVars = await buildPortEnvVars(ports); - const depsEnvVars = await buildEnvVars(cleanDependencies(deps, ports), network); - const envVars = [...depsEnvVars, ...portEnvVars]; - const cardanoNode = cardanoNodeDep(deps); + const envVars = [...portEnvVars]; const cardanoNodePort = portExists(ports, 'CardanoNodePort'); - const volumesList = workloadVolumes(name, !!cardanoNode || !!cardanoNodePort); - const containerList = containers(spec, envVars, cardanoNode, cardanoNodePort); + const volumesList = workloadVolumes(name, !!cardanoNodePort); + const containerList = containers(spec, envVars, cardanoNodePort); try { await apps.readNamespacedStatefulSet(name, ns); //@TODO sync @@ -341,12 +337,7 @@ function pvc(name: string, spec: BackendWithStorage.Spec): V1PersistentVolumeCla }; } -function containers( - spec: BackendWithStorage.Spec, - envVars: V1EnvVar[], - cardanoNodeDep: { dependency: DependencyResource; service: ServicePlugin } | null, - cardanoNodePort: ServiceInstanceWithStatusAndKind | null, -): V1Container[] { +function containers(spec: BackendWithStorage.Spec, envVars: V1EnvVar[], cardanoNodePort: ServiceInstanceWithStatusAndKind | null): V1Container[] { const args = spec.args ? spec.args.split(' ') : []; const command = spec.command ? spec.command.split(' ') : []; @@ -361,7 +352,7 @@ function containers( }, ]; - if (!!cardanoNodePort || !!cardanoNodeDep) { + if (!!cardanoNodePort) { volumeMounts.push({ name: 'ipc', mountPath: '/ipc', @@ -383,8 +374,6 @@ function containers( if (!!cardanoNodePort) { containers.push(buildSocatContainerForPort(cardanoNodePort)); - } else if (!!cardanoNodeDep) { - containers.push(buildSocatContainer(cardanoNodeDep.dependency, cardanoNodeDep.service)); } return containers; diff --git a/operator/src/backend/handlers.ts b/operator/src/backend/handlers.ts index 63f2bd0..9bffac4 100644 --- a/operator/src/backend/handlers.ts +++ b/operator/src/backend/handlers.ts @@ -1,8 +1,7 @@ import { PatchUtils, V1Container, V1EnvVar, V1Volume, V1VolumeMount, V1Deployment } from '@kubernetes/client-node'; -import { getClients, Network, DependencyResource, ServicePlugin } from '@demeter-sdk/framework'; +import { getClients, Network } from '@demeter-sdk/framework'; import { API_VERSION, API_GROUP, PLURAL } from './constants'; -import { CustomResource, CustomResourceResponse, Backend, Pod, WorkloadStatus } from '@demeter-run/workloads-types'; -import { buildEnvVars, cardanoNodeDep, cleanDependencies, getDependenciesForNetwork } from '../shared/dependencies'; +import { CustomResource, CustomResourceResponse, Backend, WorkloadStatus } from '@demeter-run/workloads-types'; import { generateProjectSpec, getComputeDCUPerMin, @@ -12,7 +11,7 @@ import { workloadVolumes, } from '../shared'; import { checkConfigMapExistsOrCreate, configmap } from '../shared/configmap'; -import { buildSocatContainer, buildSocatContainerForPort } from '../shared/cardano-node-helper'; +import { buildSocatContainerForPort } from '../shared/cardano-node-helper'; import { buildPortEnvVars, getPortsForNetwork, portExists } from '../shared/ports'; import { ServiceInstanceWithStatusAndKind } from '../services'; @@ -48,15 +47,12 @@ export async function handleResource( const project = generateProjectSpec(owner.metadata?.namespace!); const network = getNetworkFromAnnotations(spec.annotations) as Network; - const deps = await getDependenciesForNetwork(project, network); const ports = await getPortsForNetwork(project, network); const portEnvVars = await buildPortEnvVars(ports); - const depsEnvVars = await buildEnvVars(cleanDependencies(deps, ports), network); - const envVars = [...depsEnvVars, ...portEnvVars]; - const cardanoNode = cardanoNodeDep(deps); + const envVars = [...portEnvVars]; const cardanoNodePort = portExists(ports, 'CardanoNodePort'); - const volumesList = workloadVolumes(name, !!cardanoNode || !!cardanoNodePort); - const containerList = containers(spec, envVars, cardanoNode, cardanoNodePort); + const volumesList = workloadVolumes(name, !!cardanoNodePort); + const containerList = containers(spec, envVars, cardanoNodePort); try { await apps.readNamespacedDeployment(name, ns); await checkConfigMapExistsOrCreate(core, ns, name, spec, owner); @@ -228,12 +224,7 @@ function deployment( }; } -function containers( - spec: Backend.Spec, - envVars: V1EnvVar[], - cardanoNodeDep: { dependency: DependencyResource; service: ServicePlugin } | null, - cardanoNodePort: ServiceInstanceWithStatusAndKind | null, -): V1Container[] { +function containers(spec: Backend.Spec, envVars: V1EnvVar[], cardanoNodePort: ServiceInstanceWithStatusAndKind | null): V1Container[] { const args = spec.args ? spec.args.split(' ') : []; const command = spec.command ? spec.command.split(' ') : []; @@ -244,7 +235,7 @@ function containers( }, ]; - if (!!cardanoNodePort || !!cardanoNodeDep) { + if (!!cardanoNodePort) { volumeMounts.push({ name: 'ipc', mountPath: '/ipc', @@ -266,8 +257,6 @@ function containers( if (!!cardanoNodePort) { containers.push(buildSocatContainerForPort(cardanoNodePort)); - } else if (!!cardanoNodeDep) { - containers.push(buildSocatContainer(cardanoNodeDep.dependency, cardanoNodeDep.service)); } return containers; diff --git a/operator/src/frontend/handlers.ts b/operator/src/frontend/handlers.ts index 06588cc..22bb653 100644 --- a/operator/src/frontend/handlers.ts +++ b/operator/src/frontend/handlers.ts @@ -1,11 +1,17 @@ import { PatchUtils, V1Container, V1EnvVar, V1Volume, V1VolumeMount, V1Deployment } from '@kubernetes/client-node'; -import { getClients, Network, DependencyResource, ServicePlugin } from '@demeter-sdk/framework'; +import { getClients, Network } from '@demeter-sdk/framework'; import { API_VERSION, API_GROUP, PLURAL } from './constants'; import { CustomResource, CustomResourceResponse, Frontend, WorkloadStatus } from '@demeter-run/workloads-types'; -import { buildEnvVars, cardanoNodeDep, cleanDependencies, getDependenciesForNetwork } from '../shared/dependencies'; -import { generateProjectSpec, getComputeDCUPerMin, getDeploymentStatus, getNetworkFromAnnotations, getResourcesFromComputeClass, workloadVolumes } from '../shared'; +import { + generateProjectSpec, + getComputeDCUPerMin, + getDeploymentStatus, + getNetworkFromAnnotations, + getResourcesFromComputeClass, + workloadVolumes, +} from '../shared'; import { checkConfigMapExistsOrCreate, configmap } from '../shared/configmap'; -import { buildSocatContainer, buildSocatContainerForPort } from '../shared/cardano-node-helper'; +import { buildSocatContainerForPort } from '../shared/cardano-node-helper'; import { buildPortEnvVars, getPortsForNetwork, portExists } from '../shared/ports'; import { ServiceInstanceWithStatusAndKind } from '../services'; @@ -45,15 +51,12 @@ export async function handleResource( } const network = getNetworkFromAnnotations(spec.annotations) as Network; - const deps = await getDependenciesForNetwork(project, network); const ports = await getPortsForNetwork(project, network); const portEnvVars = await buildPortEnvVars(ports); - const depsEnvVars = await buildEnvVars(cleanDependencies(deps, ports), network); - const envVars = [...depsEnvVars, ...portEnvVars]; - const cardanoNode = cardanoNodeDep(deps); + const envVars = [...portEnvVars]; const cardanoNodePort = portExists(ports, 'CardanoNodePort'); - const volumesList = workloadVolumes(name, !!cardanoNode || !!cardanoNodePort); - const containerList = containers(spec, envVars, cardanoNode, cardanoNodePort); + const volumesList = workloadVolumes(name, !!cardanoNodePort); + const containerList = containers(spec, envVars, cardanoNodePort); try { await apps.readNamespacedDeployment(name, ns); await checkConfigMapExistsOrCreate(core, ns, name, spec, owner); @@ -210,12 +213,7 @@ function deployment( }; } -function containers( - spec: Frontend.Spec, - envVars: V1EnvVar[], - cardanoNodeDep: { dependency: DependencyResource; service: ServicePlugin } | null, - cardanoNodePort: ServiceInstanceWithStatusAndKind | null, -): V1Container[] { +function containers(spec: Frontend.Spec, envVars: V1EnvVar[], cardanoNodePort: ServiceInstanceWithStatusAndKind | null): V1Container[] { const args = spec.args ? spec.args.split(' ') : []; const command = spec.command ? spec.command.split(' ') : []; @@ -226,7 +224,7 @@ function containers( }, ]; - if (!!cardanoNodePort || !!cardanoNodeDep) { + if (!!cardanoNodePort) { volumeMounts.push({ name: 'ipc', mountPath: '/ipc', @@ -248,8 +246,6 @@ function containers( if (!!cardanoNodePort) { containers.push(buildSocatContainerForPort(cardanoNodePort)); - } else if (!!cardanoNodeDep) { - containers.push(buildSocatContainer(cardanoNodeDep.dependency, cardanoNodeDep.service)); } return containers; diff --git a/operator/src/shared/dependencies.ts b/operator/src/shared/dependencies.ts deleted file mode 100644 index 206b43d..0000000 --- a/operator/src/shared/dependencies.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { DependencyResource, listDependencies, loadDependencyConnections, Network, ProjectSpec, ServicePlugin } from '@demeter-sdk/framework'; -import { V1EnvVar } from '@kubernetes/client-node'; -import { getService, ServiceInstanceWithStatusAndKind } from '../services'; -import { getNetworkFromAnnotations } from '.'; -import { getCardanoNodeEnvVars } from './cardano-node-helper'; -import { portExists } from './ports'; - -export async function getDependenciesForNetwork(project: ProjectSpec, network: Network) { - const deps = await listDependencies(project); - - return deps.filter(d => getNetworkFromAnnotations(d.spec.annotations!) === network); -} - -export function isCardanoNodeEnabled(deps: DependencyResource[]): boolean { - for (const dep of deps) { - const service = getService(dep.spec.serviceId); - if (!service) continue; - if (service.metadata.kind === 'CardanoNode') { - return true; - } - } - return false; -} - -export function cardanoNodeDep(deps: DependencyResource[]): { dependency: DependencyResource; service: ServicePlugin } | null { - for (const dep of deps) { - const service = getService(dep.spec.serviceId); - if (!service) continue; - if (service.metadata.kind === 'CardanoNode') { - return { dependency: dep, service }; - } - } - return null; -} - -export async function buildEnvVars(deps: DependencyResource[], network: Network): Promise { - const output = []; - - for (const dep of deps) { - const service = getService(dep.spec.serviceId); - if (!service) continue; - if (service.metadata.kind === 'CardanoNode') { - const envVars = getCardanoNodeEnvVars(dep, service); - output.push(...envVars); - } - const connections = loadDependencyConnections(dep, service.metadata); - for (const connection of connections) { - if (connection.envVars) { - output.push(...connection.envVars); - } - } - } - return output; -} - -// check if we should filter some dependencies because ports exists - -export function cleanDependencies(deps: DependencyResource[], ports: ServiceInstanceWithStatusAndKind[]): DependencyResource[] { - const depsToIgnore: string[] = []; - if (portExists(ports, 'CardanoNodePort')) { - depsToIgnore.push('CardanoNode'); - } - if (portExists(ports, 'MarlowePort')) { - depsToIgnore.push('Marlowe'); - } - - return deps.filter(dep => !depsToIgnore.includes(dep.spec.serviceKind)); -} diff --git a/operator/src/workspaces/handlers.ts b/operator/src/workspaces/handlers.ts index 8906197..2390397 100644 --- a/operator/src/workspaces/handlers.ts +++ b/operator/src/workspaces/handlers.ts @@ -9,10 +9,9 @@ import { V1Ingress, V1Service, } from '@kubernetes/client-node'; -import { getClients, Network, ServicePlugin, DependencyResource } from '@demeter-sdk/framework'; +import { getClients, Network } from '@demeter-sdk/framework'; import { API_VERSION, API_GROUP, PLURAL, SINGULAR, KIND, DEFAULT_VSCODE_IMAGE } from './constants'; import { CustomResource, Workspace, StorageClass, CustomResourceResponse } from '@demeter-run/workloads-types'; -import { buildEnvVars, cardanoNodeDep, cleanDependencies, getDependenciesForNetwork } from '../shared/dependencies'; import { generateProjectSpec, getComputeDCUPerMin, @@ -25,7 +24,7 @@ import { loadPods, } from '../shared'; import { buildDefaultEnvVars, buildDnsZone, INITIAL_ENV_VAR_NAMES } from './helpers'; -import { buildSocatContainer, buildSocatContainerForPort } from '../shared/cardano-node-helper'; +import { buildSocatContainerForPort } from '../shared/cardano-node-helper'; import { buildPortEnvVars, getPortsForNetwork, portExists } from '../shared/ports'; import { ServiceInstanceWithStatusAndKind } from '../services'; @@ -65,16 +64,13 @@ export async function handleResource( } const network = getNetworkFromAnnotations(spec.annotations) as Network; - const deps = await getDependenciesForNetwork(project, network); const ports = await getPortsForNetwork(project, network); const portEnvVars = await buildPortEnvVars(ports); const defaultEnvVars = buildDefaultEnvVars(spec); - const depsEnvVars = await buildEnvVars(cleanDependencies(deps, ports), network); - const envVars = [...depsEnvVars, ...defaultEnvVars, ...portEnvVars]; - const cardanoNode = cardanoNodeDep(deps); + const envVars = [...defaultEnvVars, ...portEnvVars]; const cardanoNodePort = portExists(ports, 'CardanoNodePort'); - const volumesList = volumes(!!cardanoNode || !!cardanoNodePort); - const containerList = containers(spec, envVars, cardanoNode, cardanoNodePort); + const volumesList = volumes(!!cardanoNodePort); + const containerList = containers(spec, envVars, cardanoNodePort); try { await apps.readNamespacedStatefulSet(name, ns); await updateResource(ns, name, spec, containerList, volumesList, owner); @@ -430,9 +426,7 @@ function getImageFromSpec(spec: Workspace.Spec): string { function containers( spec: Workspace.Spec, envVars: V1EnvVar[], - cardanoNodeDep: { dependency: DependencyResource; service: ServicePlugin } | null, cardanoNodePort: ServiceInstanceWithStatusAndKind | null, - patch?: boolean, ): V1Container[] { const volumeMounts: V1VolumeMount[] = [ { @@ -441,7 +435,7 @@ function containers( }, ]; - if (!!cardanoNodePort || !!cardanoNodeDep) { + if (!!cardanoNodePort) { volumeMounts.push({ name: 'ipc', mountPath: '/ipc', @@ -470,8 +464,6 @@ function containers( if (!!cardanoNodePort) { containers.push(buildSocatContainerForPort(cardanoNodePort)); - } else if (!!cardanoNodeDep) { - containers.push(buildSocatContainer(cardanoNodeDep.dependency, cardanoNodeDep.service)); } return containers;