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

Remove DevClusters #441

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Remove DevClusters.
  • Loading branch information
panuhorsmalahti committed Feb 9, 2023
commit 6e5cb44213cea4c2e411f84ad731e154b385aeaf
21 changes: 1 addition & 20 deletions src/K8sCluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,12 @@ import type { Space, SpaceEntity } from "./SpaceService";
import type { MapToEntity } from "./types/types";
import type { Except } from "type-fest";

// State of the DevCluster CRD
export type DevClusterCrdState =
| "Provisioning"
| "Reprovisioning"
| "Starting"
| "Running"
| "Stopping"
| "Stopped"
| "Terminating"
| "Terminated";

// Possible status.phase of the K8sCluster in the backend
// This can be any CrdState and the others listed here.
// UI can in addition show "deleting", "connecting", "connected", "disconnected" as per typing in Lens.
export type Phase =
| Lowercase<DevClusterCrdState>
// Initial state is empty
| ""
| "initializing"
| "available"
| "failed"
| "tunneling";
"" | "initializing" | "available" | "failed" | "tunneling";

/**
*
Expand Down Expand Up @@ -55,6 +39,3 @@ export interface K8sCluster {
export type K8sClusterEntity = Except<MapToEntity<K8sCluster>, "space"> & {
space?: SpaceEntity;
};

export const isDevCluster = (k8sCluster: K8sCluster | K8sClusterEntity) =>
k8sCluster.kind === "K8sCluster" && k8sCluster.metadata?.labels?.devCluster === "true";
202 changes: 2 additions & 200 deletions src/Permissions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,6 @@ const mockK8sCluster1: K8sCluster = {
name: "",
kind: "K8sCluster",
};
const mockDevCluster1: K8sCluster = {
id: "mk1",
createdById: memberUser.id,
name: "",
kind: "K8sCluster",
metadata: {
labels: {
devCluster: "true",
},
},
};
const mockDevCluster2: K8sCluster = {
id: "mk1",
createdById: mockUser5.id,
name: "",
kind: "K8sCluster",
metadata: {
labels: {
devCluster: "true",
},
},
};

const invitationToBeRevokedByMockUser3 = "invitation_id_to_be_revoked_by_user_3";
const invitationIdsCreatedByMockUser3 = [invitationToBeRevokedByMockUser3, "another_invitation_id"];
Expand Down Expand Up @@ -538,7 +516,7 @@ describe("PermissionsService", () => {
});

describe("AccessK8sCluster", () => {
it("user can access non-devCluster", () => {
it("user can access cluster", () => {
expect(
client.permission.canK8sCluster(
K8sClusterActions.AccessK8sCluster,
Expand All @@ -548,98 +526,10 @@ describe("PermissionsService", () => {
),
).toBeTruthy();
});

it("user can access own devCluster", () => {
expect(
client.permission.canK8sCluster(
K8sClusterActions.AccessK8sCluster,
mockSpace1,
mockDevCluster1,
memberUser.id!,
),
).toBeTruthy();
});

it("user can access own devCluster 2", () => {
expect(
client.permission.canK8sCluster(
K8sClusterActions.AccessK8sCluster,
mockSpace1,
mockDevCluster2,
mockUser5.id!,
),
).toBeTruthy();
});

it("member can't access another user's devCluster", () => {
expect(
client.permission.canK8sCluster(
K8sClusterActions.AccessK8sCluster,
mockSpace1,
mockDevCluster1,
mockUser5.id!,
),
).toBeFalsy();
});

it("member can't access another user's devCluster 2", () => {
expect(
client.permission.canK8sCluster(
K8sClusterActions.AccessK8sCluster,
mockSpace1,
mockDevCluster2,
memberUser.id!,
),
).toBeFalsy();
});

it("admin can access own devCluster", () => {
expect(
client.permission.canK8sCluster(
K8sClusterActions.AccessK8sCluster,
mockSpace1,
mockDevCluster1,
adminUser.id!,
),
).toBeTruthy();
});

it("admin can access another user's devCluster", () => {
expect(
client.permission.canK8sCluster(
K8sClusterActions.AccessK8sCluster,
mockSpace1,
mockDevCluster2,
adminUser.id!,
),
).toBeTruthy();
});

it("owner can access own devCluster", () => {
expect(
client.permission.canK8sCluster(
K8sClusterActions.AccessK8sCluster,
mockSpace1,
mockDevCluster1,
ownerUser.id!,
),
).toBeTruthy();
});

it("owner can access another user's devCluster", () => {
expect(
client.permission.canK8sCluster(
K8sClusterActions.AccessK8sCluster,
mockSpace1,
mockDevCluster2,
ownerUser.id!,
),
).toBeTruthy();
});
});

describe("PatchK8sCluster", () => {
it("user can patch non-devCluster", () => {
it("user can patch cluster", () => {
expect(
client.permission.canK8sCluster(
K8sClusterActions.PatchK8sCluster,
Expand All @@ -649,94 +539,6 @@ describe("PermissionsService", () => {
),
).toBeTruthy();
});

it("user can patch own devCluster", () => {
expect(
client.permission.canK8sCluster(
K8sClusterActions.PatchK8sCluster,
mockSpace1,
mockDevCluster1,
memberUser.id!,
),
).toBeTruthy();
});

it("user can patch own devCluster 2", () => {
expect(
client.permission.canK8sCluster(
K8sClusterActions.PatchK8sCluster,
mockSpace1,
mockDevCluster2,
mockUser5.id!,
),
).toBeTruthy();
});

it("member can't patch another user's devCluster", () => {
expect(
client.permission.canK8sCluster(
K8sClusterActions.PatchK8sCluster,
mockSpace1,
mockDevCluster1,
mockUser5.id!,
),
).toBeFalsy();
});

it("member can't patch another user's devCluster 2", () => {
expect(
client.permission.canK8sCluster(
K8sClusterActions.PatchK8sCluster,
mockSpace1,
mockDevCluster2,
memberUser.id!,
),
).toBeFalsy();
});

it("admin can patch own devCluster", () => {
expect(
client.permission.canK8sCluster(
K8sClusterActions.PatchK8sCluster,
mockSpace1,
mockDevCluster1,
adminUser.id!,
),
).toBeTruthy();
});

it("admin can patch another user's devCluster", () => {
expect(
client.permission.canK8sCluster(
K8sClusterActions.PatchK8sCluster,
mockSpace1,
mockDevCluster2,
adminUser.id!,
),
).toBeTruthy();
});

it("owner can patch own devCluster", () => {
expect(
client.permission.canK8sCluster(
K8sClusterActions.PatchK8sCluster,
mockSpace1,
mockDevCluster1,
ownerUser.id!,
),
).toBeTruthy();
});

it("owner can patch another user's devCluster", () => {
expect(
client.permission.canK8sCluster(
K8sClusterActions.PatchK8sCluster,
mockSpace1,
mockDevCluster2,
ownerUser.id!,
),
).toBeTruthy();
});
});
});
});
10 changes: 3 additions & 7 deletions src/Permissions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Space, SpaceEntity } from "./SpaceService";
import type { Team, TeamEntity } from "./TeamService";
import { isDevCluster, K8sCluster, K8sClusterEntity } from "./K8sCluster";
import { K8sCluster, K8sClusterEntity } from "./K8sCluster";

export enum Roles {
Admin = "Admin",
Expand Down Expand Up @@ -211,16 +211,12 @@ export class Permissions {

switch (action) {
// Check if user can access the K8sCluster assuming the Space is accessible
// DevCluster K8sClusters can only be accessed by the creator or Admin/Owner
case K8sClusterActions.AccessK8sCluster:
canI =
!isDevCluster(forK8sCluster) || isOwnerAdmin || forK8sCluster.createdById === forUserId;
canI = true;
break;
// Check if user can patch the K8sCluster assuming the Space is accessible
// DevCluster K8sClusters can only be patched by the creator or Admin/Owner
case K8sClusterActions.PatchK8sCluster:
canI =
!isDevCluster(forK8sCluster) || isOwnerAdmin || forK8sCluster.createdById === forUserId;
canI = true;
break;

// Admin, Owner or K8sCluster creator can delete it
Expand Down
2 changes: 1 addition & 1 deletion src/SpaceService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import type { Except } from "type-fest";
export const spaceKinds = ["Personal", "Team"] as const;
export type SpaceKind = typeof spaceKinds[number];

export const spaceFeatures = ["DevCluster"] as const;
export const spaceFeatures = [] as const;
export type SpaceFeature = typeof spaceFeatures[number];

/**
Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { BillingPlan } from "./BillingPlan";
import type { InvitationDomain, InvitationDomainEntity } from "./InvitationDomain";
import type { Invitation, InvitationEntity } from "./InvitationService";
import type { DevClusterCrdState, K8sCluster, K8sClusterEntity, Phase } from "./K8sCluster";
import type { K8sCluster, K8sClusterEntity, Phase } from "./K8sCluster";
import type { LensPlatformClientOptions, LensPlatformClientType } from "./LensPlatformClient";
import LensPlatformClient from "./LensPlatformClient";
import type { OpenIdConnectUserInfo } from "./OpenIdConnect";
Expand Down Expand Up @@ -44,7 +44,6 @@ export type {
K8sClusterEntity,
InvitationEntity,
InvitationDomainEntity,
DevClusterCrdState,
Phase,
SubscriptionInfo,
SubscriptionSeat,
Expand Down