Skip to content

Commit

Permalink
chore: deprecate dependencies (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
avatxus authored Aug 29, 2024
1 parent b05c469 commit 3d94222
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 138 deletions.
25 changes: 7 additions & 18 deletions operator/src/backend-with-storage/handlers.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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';

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(' ') : [];

Expand All @@ -361,7 +352,7 @@ function containers(
},
];

if (!!cardanoNodePort || !!cardanoNodeDep) {
if (!!cardanoNodePort) {
volumeMounts.push({
name: 'ipc',
mountPath: '/ipc',
Expand All @@ -383,8 +374,6 @@ function containers(

if (!!cardanoNodePort) {
containers.push(buildSocatContainerForPort(cardanoNodePort));
} else if (!!cardanoNodeDep) {
containers.push(buildSocatContainer(cardanoNodeDep.dependency, cardanoNodeDep.service));
}

return containers;
Expand Down
27 changes: 8 additions & 19 deletions operator/src/backend/handlers.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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';

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(' ') : [];

Expand All @@ -244,7 +235,7 @@ function containers(
},
];

if (!!cardanoNodePort || !!cardanoNodeDep) {
if (!!cardanoNodePort) {
volumeMounts.push({
name: 'ipc',
mountPath: '/ipc',
Expand All @@ -266,8 +257,6 @@ function containers(

if (!!cardanoNodePort) {
containers.push(buildSocatContainerForPort(cardanoNodePort));
} else if (!!cardanoNodeDep) {
containers.push(buildSocatContainer(cardanoNodeDep.dependency, cardanoNodeDep.service));
}

return containers;
Expand Down
34 changes: 15 additions & 19 deletions operator/src/frontend/handlers.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(' ') : [];

Expand All @@ -226,7 +224,7 @@ function containers(
},
];

if (!!cardanoNodePort || !!cardanoNodeDep) {
if (!!cardanoNodePort) {
volumeMounts.push({
name: 'ipc',
mountPath: '/ipc',
Expand All @@ -248,8 +246,6 @@ function containers(

if (!!cardanoNodePort) {
containers.push(buildSocatContainerForPort(cardanoNodePort));
} else if (!!cardanoNodeDep) {
containers.push(buildSocatContainer(cardanoNodeDep.dependency, cardanoNodeDep.service));
}

return containers;
Expand Down
68 changes: 0 additions & 68 deletions operator/src/shared/dependencies.ts

This file was deleted.

20 changes: 6 additions & 14 deletions operator/src/workspaces/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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';

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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[] = [
{
Expand All @@ -441,7 +435,7 @@ function containers(
},
];

if (!!cardanoNodePort || !!cardanoNodeDep) {
if (!!cardanoNodePort) {
volumeMounts.push({
name: 'ipc',
mountPath: '/ipc',
Expand Down Expand Up @@ -470,8 +464,6 @@ function containers(

if (!!cardanoNodePort) {
containers.push(buildSocatContainerForPort(cardanoNodePort));
} else if (!!cardanoNodeDep) {
containers.push(buildSocatContainer(cardanoNodeDep.dependency, cardanoNodeDep.service));
}

return containers;
Expand Down

0 comments on commit 3d94222

Please sign in to comment.