Skip to content
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
6 changes: 3 additions & 3 deletions plugins/aks-desktop/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import ScalingTab from './components/Scaling/ScalingTab';
import type { ProjectDefinition } from './types/project';
import { getLoginStatus } from './utils/azure/az-auth';
import { AZURE_ACCOUNT_POLL_INTERVAL_MS } from './utils/constants/timing';
import { isAksProject } from './utils/shared/isAksProject';
import { isAksProject, isArmManagedProject } from './utils/shared/isAksProject';
import { azureTheme } from './utils/shared/theme';

Headlamp.setAppMenu(menus => {
Expand Down Expand Up @@ -404,8 +404,8 @@ registerProjectHeaderAction({
),
});

// Register custom delete button for AKS projects only
// Register custom delete button for AKS Desktop + ARM-managed projects only
registerProjectDeleteButton({
isEnabled: isAksProject,
isEnabled: isArmManagedProject,
component: ({ project }) => <AKSProjectDeleteButton project={project} />,
});
3 changes: 3 additions & 0 deletions plugins/aks-desktop/src/utils/constants/projectLabels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ export const SUBSCRIPTION_LABEL = 'aks-desktop/project-subscription';

/** Kubernetes label key: the Azure resource group associated with the project. */
export const RESOURCE_GROUP_LABEL = 'aks-desktop/project-resource-group';

/** Kubernetes label key: whether the namespace is managed by ARM. */
export const MANAGED_BY_ARM_LABEL = 'kubernetes.azure.com/managedByArm';
33 changes: 31 additions & 2 deletions plugins/aks-desktop/src/utils/shared/isAksProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
import { K8s } from '@kinvolk/headlamp-plugin/lib';
import type { ApiClient } from '@kinvolk/headlamp-plugin/lib/lib/k8s/api/v1/factories';
import type { KubeNamespace } from '@kinvolk/headlamp-plugin/lib/lib/k8s/namespace';
import { PROJECT_MANAGED_BY_LABEL, PROJECT_MANAGED_BY_VALUE } from '../constants/projectLabels';
import {
MANAGED_BY_ARM_LABEL,
PROJECT_MANAGED_BY_LABEL,
PROJECT_MANAGED_BY_VALUE,
} from '../constants/projectLabels';

/** Checks if the given project is an AKS desktop managed namespace project */
/** Checks if the given project is an AKS Desktop project (managed-by: aks-desktop). */
export const isAksProject = ({
project,
}: {
Expand All @@ -27,3 +31,28 @@ export const isAksProject = ({
project.clusters[0]
);
});

/** Checks if the given project is an AKS Desktop + ARM-managed namespace. */
export const isArmManagedProject = ({
project,
}: {
project: { namespaces: string[]; clusters: string[] };
}): Promise<boolean> =>
new Promise<boolean>(resolve => {
const cancelFn = (K8s.ResourceClasses.Namespace.apiEndpoint as ApiClient<KubeNamespace>).get(
project.namespaces[0],
ns => {
resolve(
ns.metadata?.labels?.[PROJECT_MANAGED_BY_LABEL] === PROJECT_MANAGED_BY_VALUE &&
ns.metadata?.labels?.[MANAGED_BY_ARM_LABEL] === 'true'
);
cancelFn.then(it => it());
},
() => {
cancelFn.then(it => it());
resolve(false);
Comment thread
tejhan marked this conversation as resolved.
},
Comment thread
tejhan marked this conversation as resolved.
{},
project.clusters[0]
);
});
Loading