diff --git a/examples/create-postgres.ts b/examples/create-postgres.ts deleted file mode 100644 index 62bbdd8..0000000 --- a/examples/create-postgres.ts +++ /dev/null @@ -1,30 +0,0 @@ -// Using the first argument as cluster id, create a postgres addon - -import { VendorPortalApi } from "../dist/configuration"; -import { createAddonPostgres, pollForAddonStatus } from "../dist/clusters"; - -// get first argument from command line as cluster id -if (process.argv.length < 3) { - console.error("Usage: node create-postgres.js "); - process.exit(1); -} -const clusterId = process.argv[2]; - -const api = new VendorPortalApi(); -api.apiToken = process.env.REPLICATED_API_TOKEN ?? ""; - -createAddonPostgres(api, clusterId) - .then(addon => { - console.log(`Postgres created: ${addon.id}`); - // Poll till addon is ready - pollForAddonStatus(api, clusterId, addon.id, "ready", 240) - .then(() => { - console.log("Postgres is ready"); - }) - .catch(err => { - console.error("Error polling for postgres status:", err); - }); - }) - .catch(err => { - console.error("Error creating postgres:", err); - }); diff --git a/src/clusters.spec.ts b/src/clusters.spec.ts index d0141d2..d8811f4 100644 --- a/src/clusters.spec.ts +++ b/src/clusters.spec.ts @@ -1,6 +1,6 @@ import { VendorPortalApi } from "./configuration"; import { createCluster, createClusterWithLicense, upgradeCluster, pollForStatus } from "."; -import { Addon, Cluster, ClusterPort, StatusError, createAddonObjectStore, createAddonPostgres, exposeClusterPort, pollForAddonStatus } from "./clusters"; +import { Addon, Cluster, ClusterPort, StatusError, createAddonObjectStore, exposeClusterPort, pollForAddonStatus } from "./clusters"; import * as mockttp from "mockttp"; describe("ClusterService", () => { @@ -226,29 +226,6 @@ describe("Cluster Add-ons", () => { expect(addon.object_store).toEqual(expectedAddon.addon.object_store); }); - test("should return postgres add-on", async () => { - const clusterId = "1234abcd"; - const expectedAddon = { - addon: { - id: "abcd1234", - status: "applied", - postgres: { - uri: "postgres://postgres:1234@test:5432", - version: "16.2", - instance_type: "db.t3.micro", - disk_gib: 200 - } - } - }; - - await mockServer.forPost(`/cluster/${clusterId}/addons/postgres`).thenReply(201, JSON.stringify(expectedAddon)); - - const addon: Addon = await createAddonPostgres(apiClient, clusterId); - expect(addon.id).toEqual(expectedAddon.addon.id); - expect(addon.status).toEqual(expectedAddon.addon.status); - expect(addon.postgres).toEqual(expectedAddon.addon.postgres); - }); - test("should eventually return success with expected status", async () => { const clusterId = "1234abcd"; const expectedAddon = { id: "1234abcd", status: "ready" }; diff --git a/src/clusters.ts b/src/clusters.ts index f1c340a..0e572a8 100644 --- a/src/clusters.ts +++ b/src/clusters.ts @@ -330,47 +330,6 @@ export async function createAddonObjectStore(vendorPortalApi: VendorPortalApi, c return addon; } -export async function createAddonPostgres(vendorPortalApi: VendorPortalApi, clusterId: string, version?: string, instanceType?: string, diskGib?: number): Promise { - const http = await vendorPortalApi.client(); - - const uri = `${vendorPortalApi.endpoint}/cluster/${clusterId}/addons/postgres`; - - const reqBody = {}; - if (version) { - reqBody["version"] = version; - } - if (instanceType) { - reqBody["instance_type"] = instanceType; - } - if (diskGib) { - reqBody["disk_gib"] = diskGib; - } - const res = await http.post(uri, JSON.stringify(reqBody)); - if (res.message.statusCode != 201) { - let body = ""; - try { - body = await res.readBody(); - } catch (err) { - // ignore - } - throw new Error(`Failed to queue add-on create: Server responded with ${res.message.statusCode}: ${body}`); - } - - const body: any = JSON.parse(await res.readBody()); - - var addon: Addon = { id: body.addon.id, status: body.addon.status }; - if (body.addon.postgres) { - addon.postgres = { - uri: body.addon.postgres.uri, - version: body.addon.postgres.version, - instance_type: body.addon.postgres.instance_type, - disk_gib: body.addon.postgres.disk_gib - }; - } - - return addon; -} - export async function pollForAddonStatus(vendorPortalApi: VendorPortalApi, clusterId: string, addonId: string, expectedStatus: string, timeout: number = 120, sleeptimeMs: number = 5000): Promise { // get add-ons from the api, look for the status of the id to be ${status} // if it's not ${status}, sleep for 5 seconds and try again diff --git a/src/index.ts b/src/index.ts index 9a83828..29ff0b6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ export { VendorPortalApi } from "./configuration"; export { getApplicationDetails } from "./applications"; export { Channel, createChannel, getChannelDetails, archiveChannel } from "./channels"; -export { ClusterVersion, createCluster, createClusterWithLicense, pollForStatus, getKubeconfig, removeCluster, upgradeCluster, getClusterVersions, createAddonObjectStore, createAddonPostgres, pollForAddonStatus, exposeClusterPort } from "./clusters"; +export { ClusterVersion, createCluster, createClusterWithLicense, pollForStatus, getKubeconfig, removeCluster, upgradeCluster, getClusterVersions, createAddonObjectStore, pollForAddonStatus, exposeClusterPort } from "./clusters"; export { KubernetesDistribution, archiveCustomer, createCustomer, getUsedKubernetesDistributions } from "./customers"; export { Release, CompatibilityResult, createRelease, createReleaseFromChart, promoteRelease, reportCompatibilityResult } from "./releases";