Skip to content

Commit

Permalink
Update to use new kluster kubeconfig endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Rick Lane <[email protected]>
  • Loading branch information
rick-a-lane-ii committed Apr 2, 2024
1 parent a8293d4 commit 8c3e1dc
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 11 deletions.
51 changes: 40 additions & 11 deletions .github/actions/provision-cluster/lib/kubeception.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class Client {

async allocateCluster(version, lifespan) {
const clusterName = utils.getUniqueClusterName(MAX_KLUSTER_NAME_LEN);
const kubeConfig = await this.createKluster(clusterName, version, lifespan);
await this.createKluster(clusterName, version, lifespan);
const kubeConfig = await this.getKlusterKubeconfig(clusterName);
return {
name: clusterName,
config: kubeConfig,
Expand All @@ -42,11 +43,11 @@ class Client {

async createKluster(name, version, lifespan) {
if (!name) {
throw new Error("Function createKluster() needs a Kluster name");
throw new Error("Kluster name is required");
}

if (!version) {
throw Error("Function createKluster() needs a Kluster version");
throw Error("Kluster version is required");
}

if (
Expand All @@ -57,13 +58,6 @@ class Client {
lifespan = defaultLifespan;
}

const kubeceptionToken = core.getInput("kubeceptionToken");
if (!kubeceptionToken) {
throw Error(
`kubeceptionToken is missing. Make sure that input parameter kubeceptionToken was provided`
);
}

let kubeceptionProfile = core.getInput("kubeceptionProfile");
if (
typeof kubeceptionProfile !== typeof "" ||
Expand All @@ -81,6 +75,41 @@ class Client {
throw new utils.Transient("Unknown error getting response");
}

switch (response.message.statusCode) {
case 200:
case 201:
case 202:
return;
case 425:
// This will be deprecated in the future, pending rework of the API
// 425 should be treated as any other 4xx error
return;
default:
if (response.message.statusCode >= 400) {
throw new utils.Transient(
`Status code ${response.message.statusCode}`
);
} else {
throw new Error(`Status code ${response.message.statusCode}`);
}
}
});
}

async getKlusterKubeconfig(name) {
if (!name) {
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:
Expand All @@ -104,7 +133,7 @@ class Client {

async deleteKluster(name) {
if (!name) {
throw Error("Function deleteKluster() needs a Kluster name");
throw Error("Kluster name is required");
}

const response = await this.client.del(
Expand Down
7 changes: 7 additions & 0 deletions .github/actions/provision-cluster/lib/kubeception.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ test("kubeception profile", async () => {
inputs.kubeceptionProfile
);

return {
message: {
statusCode: 200,
},
};
}
async get() {
let status = 200;
if (count < 2) {
status = 425;
Expand Down

0 comments on commit 8c3e1dc

Please sign in to comment.