Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to use new kluster kubeconfig endpoint #91

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading