@demeter-features/cardano-submit-api
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -5,2 +5,3 @@ "use strict"; | ||
const _1 = require("."); | ||
const constants_1 = require("./constants"); | ||
const ui_1 = require("./ui"); | ||
@@ -34,2 +35,3 @@ // TODO: Deprecate | ||
licenseUrl: 'https://github.com/input-output-hk/cardano-node/blob/master/LICENSE', | ||
ports: [{ name: 'api', port: constants_1.CONTAINER_PORT, type: 'http', label: 'Http Port' }] | ||
}; | ||
@@ -79,3 +81,10 @@ exports.SERVICE_PLUGIN = { | ||
return (0, ui_1.getServiceInstanceDetailUI)(api); | ||
}, | ||
buildProxyDns: async function (port, dependency) { | ||
const network = dependency.annotations['cardano.demeter.run/network']; | ||
if (port.name === 'api') { | ||
return (0, _1.buildPrivateDnsFromNetwork)(network, dependency.instanceName, dependency.instanceSalt); | ||
} | ||
throw Error(`${port.name} not supported`); | ||
} | ||
}; |
import { ServiceInstance } from "@demeter-sdk/framework"; | ||
import { CustomResource } from "./model"; | ||
export declare const CONTAINER_PORT = 8090; | ||
export declare const SALT = "8o1"; | ||
export declare const CUSTOM_RESOURCE: { | ||
@@ -12,2 +14,3 @@ apiGroup: string; | ||
}; | ||
export declare const BASE_DCU_ESTIMATE = 500000; | ||
export declare function mapToServiceInstance(s: CustomResource, tenancy: 'cluster' | 'project'): ServiceInstance; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.mapToServiceInstance = exports.CUSTOM_RESOURCE = void 0; | ||
exports.mapToServiceInstance = exports.BASE_DCU_ESTIMATE = exports.CUSTOM_RESOURCE = exports.SALT = exports.CONTAINER_PORT = void 0; | ||
exports.CONTAINER_PORT = 8090; | ||
exports.SALT = '8o1'; | ||
exports.CUSTOM_RESOURCE = { | ||
@@ -18,4 +20,22 @@ apiGroup: 'demeter.run', | ||
} | ||
exports.BASE_DCU_ESTIMATE = 500000; | ||
/** | ||
* Estimates the DCU consumption for an instance given its configuration | ||
* for now we are just using the network as a multiplier of tha base value | ||
* @param s | ||
* @returns | ||
*/ | ||
function estimateDcu(s) { | ||
if (s.spec.network === 'preview') | ||
return exports.BASE_DCU_ESTIMATE; | ||
if (s.spec.network === 'testnet') | ||
return exports.BASE_DCU_ESTIMATE * 1.0; | ||
if (s.spec.network === 'preprod') | ||
return exports.BASE_DCU_ESTIMATE * 1.2; | ||
if (s.spec.network === 'mainnet') | ||
return exports.BASE_DCU_ESTIMATE * 3; | ||
return exports.BASE_DCU_ESTIMATE; | ||
} | ||
function mapToServiceInstance(s, tenancy) { | ||
var _a; | ||
var _a, _b, _c; | ||
return { | ||
@@ -28,2 +48,5 @@ id: (_a = s.metadata) === null || _a === void 0 ? void 0 : _a.name, | ||
privateDns: s.status.privateDns, | ||
dcuEstimate: estimateDcu(s), | ||
instanceName: (_c = (_b = s.metadata) === null || _b === void 0 ? void 0 : _b.name) === null || _c === void 0 ? void 0 : _c.split('-')[0], | ||
salt: exports.SALT, | ||
labels: { 'Network': s.spec.network }, | ||
@@ -30,0 +53,0 @@ ...s |
import type { V1Ingress, V1Service } from '@kubernetes/client-node'; | ||
import { ProjectSpec, ServiceInstance } from '@demeter-sdk/framework'; | ||
export * from './config'; | ||
@@ -18,3 +17,2 @@ export type SubmitApiStatus = { | ||
export declare function readSubmitApi(projectSlug: string, userId: string): Promise<SubmitApiStatus>; | ||
export declare function readClusterInstances(projectSpec: ProjectSpec, network: string): Promise<ServiceInstance[]>; | ||
export declare function createPort(projectSlug: string, userId: string): Promise<void>; | ||
@@ -21,0 +19,0 @@ export declare function deletePort(projectSlug: string, userId: string): Promise<void>; |
@@ -29,3 +29,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.service = exports.ingress = exports.deletePort = exports.createPort = exports.readClusterInstances = exports.readSubmitApi = exports.submitRequest = exports.buildPrivateEndpoint = exports.buildPublicEndpoint = exports.INGRESS_NAME = void 0; | ||
exports.service = exports.ingress = exports.deletePort = exports.createPort = exports.readSubmitApi = exports.submitRequest = exports.buildPrivateEndpoint = exports.buildPublicEndpoint = exports.INGRESS_NAME = void 0; | ||
const nodes = __importStar(require("@demeter-features/cardano-nodes")); | ||
@@ -117,28 +117,2 @@ const framework_1 = require("@demeter-sdk/framework"); | ||
exports.readSubmitApi = readSubmitApi; | ||
// @TODO: the project should not be sent as a parameter. As the ingress gets refactor we should | ||
// remove it from the interface | ||
async function readClusterInstances(projectSpec, network) { | ||
const { apps, net } = (0, framework_1.getClients)(); | ||
const namespace = (0, framework_1.slugToNamespace)(projectSpec.slug); | ||
const running = await readNodeRunning(apps, network); | ||
const ingress = await readPublicIngress(net, namespace); | ||
const status = { | ||
running, | ||
exposed: !!ingress, | ||
privateEndpoint: buildPrivateEndpoint(network), | ||
publicEndpoint: buildPublicEndpoint(projectSpec.slug), | ||
privateHost: nodes.defaultNodePrivateDns(network), | ||
privatePort: nodes.SUBMIT_API_PORT, | ||
}; | ||
return [{ | ||
id: `cardano-submitapi-${network}`, | ||
tenancy: 'cluster', | ||
version: `1.0.0`, | ||
privateDns: status.privateHost, | ||
runningStatus: running ? 'running' : 'not-running', | ||
annotations: { network }, | ||
...status, | ||
}]; | ||
} | ||
exports.readClusterInstances = readClusterInstances; | ||
async function createPort(projectSlug, userId) { | ||
@@ -145,0 +119,0 @@ const { net, core } = (0, framework_1.getClients)(); |
@@ -1,2 +0,2 @@ | ||
import { ProjectSpec, ServiceInstance, Tenancy } from '@demeter-sdk/framework'; | ||
import { Network, ProjectSpec, ServiceInstance, Tenancy } from '@demeter-sdk/framework'; | ||
export * from './config'; | ||
@@ -6,1 +6,2 @@ export * from './index-old'; | ||
export declare function loadInstance(projectSpec: ProjectSpec, instanceId: string, tenancy?: Tenancy): Promise<ServiceInstance | null>; | ||
export declare function buildPrivateDnsFromNetwork(network: Network, name?: string, salt?: string): Promise<string>; |
@@ -17,3 +17,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.loadInstance = exports.loadClusterInstances = void 0; | ||
exports.buildPrivateDnsFromNetwork = exports.loadInstance = exports.loadClusterInstances = void 0; | ||
const framework_1 = require("@demeter-sdk/framework"); | ||
@@ -46,1 +46,21 @@ const constants_1 = require("./constants"); | ||
exports.loadInstance = loadInstance; | ||
function buildPrivateDNS(name) { | ||
return `${name}.${constants_1.CUSTOM_RESOURCE.namespace}.svc.cluster.local`; | ||
} | ||
async function buildPrivateDnsFromNetwork(network, name, salt) { | ||
var _a; | ||
if (name && salt) { | ||
return buildPrivateDNS(`${name}-${salt}`); | ||
} | ||
if (name) { | ||
return buildPrivateDNS(name); | ||
} | ||
const { crd } = (0, framework_1.getClients)(); | ||
const res = (await crd.listNamespacedCustomObject(constants_1.CUSTOM_RESOURCE.apiGroup, constants_1.CUSTOM_RESOURCE.apiVersion, constants_1.CUSTOM_RESOURCE.namespace, constants_1.CUSTOM_RESOURCE.plural, undefined, undefined, undefined)); | ||
const match = res.body.items.filter(item => item.spec.network === network); | ||
if (match.length) { | ||
return buildPrivateDNS((_a = match[0].metadata) === null || _a === void 0 ? void 0 : _a.name); | ||
} | ||
return ''; | ||
} | ||
exports.buildPrivateDnsFromNetwork = buildPrivateDnsFromNetwork; |
{ | ||
"name": "@demeter-features/cardano-submit-api", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "license": "", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22263
517