project: Add ability to import and convert namespaces into projects #314
project: Add ability to import and convert namespaces into projects #314sniok merged 8 commits intoAzure:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request adds a new "AKS project from existing namespace" feature that enables users to convert existing AKS managed namespaces into Headlamp projects. The feature addresses the gap where namespaces created outside AKS Desktop (via Azure CLI or Portal) could not be turned into projects. The implementation follows the codebase's established patterns and successfully extracts shared role assignment logic into reusable utilities.
Changes:
- New wizard flow for converting or importing managed namespaces with 5 steps: namespace selection, networking policies, compute quota, access control, and review
- Shared utility modules for role assignment (
roleAssignment.ts) and namespace label management (namespaceUtils.ts) - Azure Resource Graph-based namespace discovery with platform-specific query quoting for Windows compatibility
- Documentation links added to README for AKS Desktop and managed namespaces
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
utils/kubernetes/namespaceUtils.ts |
New utility for fetching namespace data via K8s API and applying project labels |
utils/azure/roleAssignment.ts |
Extracted shared role assignment logic from CreateAKSProject into reusable utility function |
hooks/useNamespaceDiscovery.ts |
New hook that discovers managed namespaces via Azure Resource Graph with categorization |
components/NamespaceSelectionStep.tsx |
Namespace picker UI with radio selection tables for conversion vs import categories |
components/FromNamespaceReviewStep.tsx |
Review step displaying labels, config, and user assignments before conversion |
CreateProjectFromNamespace.tsx |
Main wizard component orchestrating the 5-step conversion/import flow |
index.tsx |
Route and custom create project registration for new namespace conversion feature |
CreateAKSProject.tsx |
Refactored to use shared assignRolesToNamespace utility, reducing duplication |
README.md |
Added documentation section with links to AKS Desktop and managed namespaces docs |
docs/implementation-plan-namespace-to-project.md |
Comprehensive implementation plan document (800 lines) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
plugins/aks-desktop/src/components/CreateProjectFromNamespace/hooks/useNamespaceDiscovery.ts
Outdated
Show resolved
Hide resolved
plugins/aks-desktop/src/components/CreateProjectFromNamespace/CreateProjectFromNamespace.tsx
Outdated
Show resolved
Hide resolved
plugins/aks-desktop/src/components/CreateProjectFromNamespace/CreateProjectFromNamespace.tsx
Outdated
Show resolved
Hide resolved
35b38a6 to
bf3548f
Compare
bf3548f to
ea277f2
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 29 out of 29 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
.../aks-desktop/src/components/CreateProjectFromNamespace/components/NamespaceSelectionStep.tsx
Outdated
Show resolved
Hide resolved
.../aks-desktop/src/components/CreateProjectFromNamespace/components/NamespaceSelectionStep.tsx
Outdated
Show resolved
Hide resolved
plugins/aks-desktop/src/components/ImportAKSProjects/ImportAKSProjects.tsx
Outdated
Show resolved
Hide resolved
ea277f2 to
675a74f
Compare
675a74f to
5f53f75
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 28 out of 28 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
plugins/aks-desktop/src/utils/shared/isAksProject.tsx:23
- The cancel function is not being called in the error callback. According to the codebase conventions, cancelFn must be awaited and called in both success and error callbacks to prevent resource leaks. Add
cancelFn.then(it => it());inside the error callback.
() => {
res(false);
},
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
illume
left a comment
There was a problem hiding this comment.
Can you please break this down into some smaller commits?
5f53f75 to
ec3a329
Compare
ec3a329 to
d90b62d
Compare
d90b62d to
ce30d98
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 27 out of 27 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
plugins/aks-desktop/src/components/CreateAKSProject/components/BasicsStep.tsx
Outdated
Show resolved
Hide resolved
plugins/aks-desktop/src/components/CreateAKSProject/CreateAKSProject.tsx
Outdated
Show resolved
Hide resolved
plugins/aks-desktop/src/components/ImportAKSProjects/ImportAKSProjects.tsx
Show resolved
Hide resolved
ce30d98 to
9ac09a4
Compare
9ac09a4 to
175a3c2
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 27 out of 27 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
plugins/aks-desktop/src/components/ImportAKSProjects/ImportAKSProjects.tsx
Outdated
Show resolved
Hide resolved
plugins/aks-desktop/src/components/ImportAKSProjects/components/ConversionDialog.test.tsx
Outdated
Show resolved
Hide resolved
0f43e69 to
b257e67
Compare
b257e67 to
0411f2c
Compare
5d82a1c to
5b5ac32
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 45 out of 46 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (4)
plugins/aks-desktop/src/components/ImportAKSProjects/ImportAKSProjects.tsx:1
- Keying
clusterMaponly byclusterNamecan conflate distinct Azure AKS clusters that share the same name across different resource groups/subscriptions. This can cause incorrect registration metadata (resourceGroup/subscriptionId) to be used for conversion/import. Use a composite key (e.g.,${clusterName}|${subscriptionId}|${resourceGroup}or an ARM ID) to keep clusters distinct.
// Copyright (c) Microsoft Corporation.
plugins/aks-desktop/src/utils/azure/roleAssignment.ts:1
- The string
No user assignments to processlooks like a new i18n key, but the locale files added in this PR includeNo users to assign(and not this exact key). To avoid untranslated UI text, either reuse the existing key (No users to assign) or add this new key to the locale files consistently.
plugins/aks-desktop/src/hooks/useNamespaceDiscovery.ts:1 isAlreadyImportedreads/parses localStorage viagetClusterSettingsfor every namespace being mapped/filtered. On clusters with many namespaces, this can add noticeable overhead. Consider cachingallowedNamespacesperclusterNamefor the duration ofdiscover()(e.g., a Map ofclusterName -> Set<string>), so each cluster’s settings are parsed once.
plugins/aks-desktop/src/hooks/useNamespaceDiscovery.ts:1- Deduplication uses
${clusterName}/${namespace}as the identity key. If two distinct clusters share the sameclusterName(possible across different Azure subscriptions/resource groups) this will incorrectly drop namespaces from the 'regular' set. Prefer a stable unique cluster identifier for managed namespaces (e.g., include subscriptionId/resourceGroup, or store/use ARM resource IDs) when generating dedupe keys.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
plugins/aks-desktop/src/components/CreateAKSProject/CreateAKSProject.tsx
Outdated
Show resolved
Hide resolved
5b5ac32 to
6391598
Compare
6391598 to
98be059
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 46 out of 47 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (4)
plugins/aks-desktop/src/utils/azure/roleAssignment.ts:1
- This introduces a new user-facing i18n key ('No user assignments to process') that doesn’t appear in the updated locale files (which include a similar 'No users to assign'). To avoid untranslated strings, reuse the existing key or add this new key to all locale dictionaries.
plugins/aks-desktop/src/utils/kubernetes/namespaceUtils.ts:1 - New behavior is introduced for creating a namespace pre-labeled as a project, but the current
namespaceUtils.test.tsonly coversfetchNamespaceDataandapplyProjectLabels. Add tests that assert thepostcall payload (labels and name) and that the correct cluster name is passed.
plugins/aks-desktop/src/hooks/useNamespaceDiscovery.ts:1 - This references
windowdirectly, which will throw in non-browser environments (e.g., if the hook is ever executed in a non-jsdom test or SSR-like context). UseglobalThisand atypeof window !== 'undefined'guard (or read fromglobalThisonly) to make the helper safe to import/execute outside the browser.
plugins/aks-desktop/src/hooks/useNamespaceDiscovery.ts:1 - If
cancel()throws or the promise chain rejects, this can surface as an unhandled rejection. Consider adding a.catch(() => {})(similar tofetchNamespaceData) to ensure cleanup never produces noisy console errors.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
98be059 to
e44e0bf
Compare
e44e0bf to
21c2c0d
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 46 out of 47 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
plugins/aks-desktop/src/utils/kubernetes/namespaceUtils.ts:1
- Error detection for
az aks namespace updateis case-sensitive and relies on the substring'ERROR'; this can miss failures that are reported with different casing or formatting (e.g.,Error:) and incorrectly treat the operation as success. Prefer checking the command exit status (ifrunCommandAsyncexposes it or rejects on non-zero), or use a case-insensitive match for common error prefixes while still allowing known warning-only stderr output.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
plugins/aks-desktop/src/components/ImportAKSProjects/ImportAKSProjects.tsx
Show resolved
Hide resolved
plugins/aks-desktop/src/components/ImportAKSProjects/ImportAKSProjects.tsx
Outdated
Show resolved
Hide resolved
21c2c0d to
ce7c894
Compare
Move hardcoded project label strings into utils/constants/projectLabels.ts and update all consumers (CreateAKSProject, DeleteAKSProject, InfoTab, Metrics, Scaling, isAksProject). Also fix useClustersConf import path.
Move the inline role assignment loop from CreateAKSProject into a reusable assignRolesToNamespace() function in utils/azure/roleAssignment.ts. This will also be used by the namespace import flow.
…ooks Add helper utilities for the namespace import feature: - namespaceUtils: fetch namespace data and apply project labels via K8s API - clusterSettings: read/write per-cluster localStorage settings - useRegisteredClusters: hook returning registered cluster names - useNamespaceDiscovery: discovers AKS managed namespaces (via Azure Resource Graph) and regular K8s namespaces, categorizing them as needing conversion or import Includes vitest config and tests for all new modules.
Rewrite the import page to use the new useNamespaceDiscovery hook, supporting both managed namespace import and regular namespace conversion to projects. Add ConversionDialog for converting unlabeled namespaces. Update plugin registration text and add documentation links to README.
Add a wizard flow for converting individual namespaces into AKS Desktop projects. Unlike the bulk ImportAKSProjects flow, this provides a guided step-by-step experience with networking, compute, and access configuration. Steps: Select Namespace → Networking → Compute → Access → Review The wizard discovers managed namespaces via Azure Resource Graph and supports both conversion (adding project labels) and import (already labeled but not registered locally). Registered as a custom create project option in the Headlamp plugin sidebar.
…ments - Replace Map<string, boolean> with Set<string> for selection state (ImportAKSProjects) - Remove unused AzureCliWarning component from ImportAKSProjects - Use i18next plural keys (_one/_other) instead of manual suffix concatenation - Replace raw <input> with MUI TextField in success dialogs (CreateAKSProject, CreateProjectFromNamespace) - Clean up timeout promise with clearTimeout in finally block - Add updateFormData to useEffect dependency array - Use theme.palette.divider instead of hardcoded border colors (FromNamespaceReviewStep) - Replace fixed height with minHeight on review cards - Remove duplicate checkAzureCliAndAksPreview mock from test - Rename isAksProject.tsx to .ts (no JSX) - Consolidate dual useMemo into single call (useNamespaceDiscovery) - Initialize loading state to true (useNamespaceDiscovery) - Use Pick<DiscoveredNamespace, ...> instead of manual interface (ConversionDialog) - Add 7 new tests: success overlay, updateManagedNamespace args, back navigation, partial role failure, cluster registration error, setClusterSettings, mixed results
ce7c894 to
df37fba
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 46 out of 47 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
plugins/aks-desktop/src/components/ImportAKSProjects/ImportAKSProjects.tsx
Outdated
Show resolved
Hide resolved
df37fba to
ea1797f
Compare
Summary
Implements the namespace-to-project conversion experience allowing users to import existing AKS managed namespaces as AKS Desktop projects.
For issue:
Unified Import Page
ImportAKSProjectsto discover all managed namespaces (not just pre-labeled ones) via Azure Resource Graphheadlamp.dev/project-managed-by: aks-desktop) before proceedingShared Utilities
assignRolesToNamespace()fromCreateAKSProjectintoutils/azure/roleAssignment.tsfor reuseapplyProjectLabels()andfetchNamespaceData()inutils/kubernetes/namespaceUtils.tsfor K8s label operationsCreateAKSProject.tsxto use the shared role assignment utility (~130 lines removed)New Components
ConversionDialog— confirmation popup disclosing which labels will be addeduseNamespaceDiscoveryhook — Resource Graph discovery withisAksProjectstatus, system namespace filtering, already-imported filteringCreateProjectFromNamespacewizard — 5-step flow for advanced conversion (namespace selection, networking, compute, access, review)Other
index.tsxFile Changes
ConversionDialog.tsx,ImportAKSProjects/hooks/useNamespaceDiscovery.ts,CreateProjectFromNamespace/(wizard + components + hook),roleAssignment.ts,namespaceUtils.tsImportAKSProjects.tsx(rewrite),CreateAKSProject.tsx(refactor),index.tsx(registrations),README.mdnamespaceUtils.test.ts(10 tests),roleAssignment.test.ts(9 tests)Test plan
ImportAKSProjectspage shows all managed namespaces with "AKS Project?" columnCreateAKSProjectwizard still works after role assignment refactor