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

feat: add space cluster kubeconfig secret endpoints #562

Merged
merged 1 commit into from
Dec 2, 2024
Merged
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
79 changes: 79 additions & 0 deletions src/SpaceService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
UserNameNotFoundException,
NotFoundException,
ClusterNotFoundException,
ForbiddenException,
} from "./exceptions";
import type { MapToEntity } from "./types/types";
import type { Except } from "type-fest";
Expand Down Expand Up @@ -221,6 +222,84 @@ class SpaceService extends Base {
return json as unknown as { token: string };
}

/**
* Create a kubeconfig by space name and cluster id
*/
async createKubeConfig({
name,
clusterId,
kubeconfig,
}: {
name: string;
clusterId: string;
kubeconfig: string;
}): Promise<{ value: string; id: string }> {
const { apiEndpointAddress, fetch } = this.lensPlatformClient;
const url = `${apiEndpointAddress}/spaces/${name}/k8sclusters/${clusterId}/kubeconfig-secret`;

const json = await throwExpected(
async () =>
fetch.post(url, {
value: kubeconfig,
}),
{
404: (error) => new NotFoundException(error?.body.message),
403: (error) => new ForbiddenException(error?.body.message),
},
);

return json as unknown as { value: string; id: string };
}

/**
* Get kubeconfig by space name and cluster id
*/
async getKubeConfig({
name,
clusterId,
}: {
name: string;
clusterId: string;
}): Promise<{ value: string; id: string }> {
const { apiEndpointAddress, fetch } = this.lensPlatformClient;
const url = `${apiEndpointAddress}/spaces/${name}/k8sclusters/${clusterId}/kubeconfig-secret`;

const json = await throwExpected(async () => fetch.get(url), {
404: (error) => new NotFoundException(error?.body.message),
403: (error) => new ForbiddenException(error?.body.message),
});

return json as unknown as { value: string; id: string };
}

/**
* Update existing kubeconfig by space name, cluster id and kubeconfig id
*/
async updateKubeConfig({
name,
clusterId,
kubeconfigId,
kubeconfig,
}: {
name: string;
clusterId: string;
kubeconfigId: string;
kubeconfig: string;
}): Promise<{ id: string; value: string }> {
const { apiEndpointAddress, fetch } = this.lensPlatformClient;
const url = `${apiEndpointAddress}/spaces/${name}/k8sclusters/${clusterId}/kubeconfig-secret`;

const json = await throwExpected(
async () => fetch.put(url, { id: kubeconfigId, value: kubeconfig }),
{
404: (error) => new NotFoundException(error?.body.message),
403: (error) => new ForbiddenException(error?.body.message),
},
);

return json as unknown as { id: string; value: string };
}

/**
* Get all clusters in one space by space name
*/
Expand Down