diff --git a/.github/actions/provision-cluster/action.yaml b/.github/actions/provision-cluster/action.yaml index 2e5211c6..81f0767e 100644 --- a/.github/actions/provision-cluster/action.yaml +++ b/.github/actions/provision-cluster/action.yaml @@ -34,10 +34,6 @@ inputs: gkeConfig: description: "A JSON string containing additional configuration for the given GKE cluster." required: false - kubeceptionProfile: - description: "The profile to use for kubeception clusters." - required: false - default: "default" useAuthProvider: description: "For GKE clusters, if true, use an authentication provider." required: false diff --git a/.github/actions/provision-cluster/lib/kubeception.js b/.github/actions/provision-cluster/lib/kubeception.js index d8e3da10..58e36df7 100644 --- a/.github/actions/provision-cluster/lib/kubeception.js +++ b/.github/actions/provision-cluster/lib/kubeception.js @@ -7,7 +7,9 @@ const utils = require("./utils.js"); const yaml = require("yaml"); const MAX_KLUSTER_NAME_LEN = 63; -const defaultLifespan = 60 * 60; // One hour worth of seconds +const DEFAULT_ARCHETYPE = "small"; +const DEFAULT_LIFESPAN = 60 * 60; +const KUBECEPTION_BASE_URL = "https://kubeception.datawire.io"; class Client { constructor(client) { @@ -47,28 +49,24 @@ class Client { } if (!version) { - throw Error("Kluster version is required"); + throw new Error("Kluster version is required"); } - if ( - typeof lifespan === typeof undefined || - lifespan === "" || - lifespan === 0 - ) { - lifespan = defaultLifespan; - } + lifespan = lifespan || DEFAULT_LIFESPAN; - let kubeceptionProfile = core.getInput("kubeceptionProfile"); - if ( - typeof kubeceptionProfile !== typeof "" || - kubeceptionProfile.trim() === "" - ) { - kubeceptionProfile = "default"; - } + const payload = { + version: version, + archetype: DEFAULT_ARCHETYPE, + timeoutSecs: lifespan, + }; return utils.fibonacciRetry(async () => { - const response = await this.client.put( - `https://sw.bakerstreet.io/kubeception/api/klusters/${name}?version=${version}&profile=${kubeceptionProfile}&timeoutSecs=${lifespan}` + const response = await this.client.post( + `${KUBECEPTION_BASE_URL}/klusters/${name}`, + JSON.stringify(payload), + { + "Content-Type": "application/json", + } ); if (!response || !response.message) { @@ -101,55 +99,61 @@ class Client { throw new Error("Kluster name is required"); } - return utils.fibonacciRetry(async () => { - const response = await this.client.get( - `https://sw.bakerstreet.io/kubeception/api/klusters/${name}/kubeconfig` - ); - - if (!response || !response.message) { - throw new utils.Transient("Unknown error getting response"); - } - - switch (response.message.statusCode) { - case 200: - case 201: - return await response.readBody(); - case 202: - throw new utils.Retry("Request is still pending"); - default: - if (response.message.statusCode >= 400) { - throw new utils.Transient( - `Status code ${response.message.statusCode}` - ); - } else { - let body = await response.readBody(); - throw new Error( - `Status code ${response.message.statusCode}: ${body}` - ); - } - } - }); + return utils.fibonacciRetry( + async () => { + const response = await this.client.get( + `${KUBECEPTION_BASE_URL}/api/klusters/${name}/kubeconfig` + ); + + if (!response || !response.message) { + throw new utils.Transient("Unknown error getting response"); + } + + switch (response.message.statusCode) { + case 200: + case 201: + return await response.readBody(); + case 202: + throw new utils.Retry("Request is still pending"); + default: + if (response.message.statusCode >= 400) { + throw new utils.Transient( + `Status code ${response.message.statusCode}` + ); + } else { + let body = await response.readBody(); + throw new Error( + `Status code ${response.message.statusCode}: ${body}` + ); + } + } + }, + 600000, + 1000, + 600000 + ); } async deleteKluster(name) { if (!name) { - throw Error("Kluster name is required"); + throw new Error("Kluster name is required"); } const response = await this.client.del( - `https://sw.bakerstreet.io/kubeception/api/klusters/${name}` + `${KUBECEPTION_BASE_URL}/api/klusters/${name}` ); + if (!response || !response.message) { - throw Error("Unknown error getting response"); + throw new Error("Unknown error getting response"); } - if (response.message.statusCode == 200) { + if (response.message.statusCode === 200) { return { done: true, status: "deleted", }; } else { - throw Error( + throw new Error( `Expected status code 200 but got ${response.message.statusCode}` ); } diff --git a/.github/actions/provision-cluster/lib/kubeception.test.js b/.github/actions/provision-cluster/lib/kubeception.test.js index 36bab30d..9727c61c 100644 --- a/.github/actions/provision-cluster/lib/kubeception.test.js +++ b/.github/actions/provision-cluster/lib/kubeception.test.js @@ -6,23 +6,16 @@ const common = require("./common_test.js"); const mock = require("./mock.js"); const MOCK = mock.MOCK; const cluster = mock.cluster; -const URL = require("url").URL; -test("kubeception profile", async () => { +test("kubeception", async () => { let inputs = { kubeceptionToken: "mock-kube-token", - kubeceptionProfile: "mock-profile", }; let count = 0; class MockHttpClient { - async put(url) { - let parsed = new URL(url); - expect(parsed.searchParams.get("profile")).toBe( - inputs.kubeceptionProfile - ); - + async post() { return { message: { statusCode: 200, diff --git a/provision-cluster/action.yaml b/provision-cluster/action.yaml index d59cec74..bd9ceb20 100644 --- a/provision-cluster/action.yaml +++ b/provision-cluster/action.yaml @@ -34,10 +34,6 @@ inputs: gkeConfig: description: "A JSON string containing additional configuration for the given GKE cluster." required: false - kubeceptionProfile: - description: "The profile to use for kubeception clusters." - required: false - default: "default" useAuthProvider: description: "For GKE clusters, if true, use an authentication provider." required: false @@ -89,5 +85,4 @@ runs: kubeceptionToken: ${{ inputs.kubeceptionToken }} gkeCredentials: ${{ inputs.gkeCredentials }} gkeConfig: ${{ inputs.gkeConfig }} - kubeceptionProfile: ${{ inputs.kubeceptionProfile }} useAuthProvider: ${{ inputs.useAuthProvider }}