Skip to content
Draft
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,14 @@ export default function ImportAKSProjects() {
continue;
}

// add allowed namespaces
const settings = JSON.parse(
localStorage.getItem(`cluster_settings.${clusterName}`) || '{}'
);
Comment on lines +264 to +266
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JSON.parse call could throw an exception if the localStorage value is not valid JSON. While the fallback of '{}' handles the case when the value doesn't exist, if the value exists but is corrupted or malformed, it will throw an error. Consider wrapping this in a try-catch block to handle potential parse errors gracefully.

Suggested change
const settings = JSON.parse(
localStorage.getItem(`cluster_settings.${clusterName}`) || '{}'
);
const rawSettings = localStorage.getItem(`cluster_settings.${clusterName}`);
let settings: any;
try {
settings = rawSettings ? JSON.parse(rawSettings) : {};
} catch {
settings = {};
}

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. It's a valid point IMHO.

settings.allowedNamespaces ??= [];
settings.allowedNamespaces.push(...namespacesInCluster.map(it => it.namespace.name));
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The allowedNamespaces array can contain duplicates if the import function is called multiple times for the same cluster. Consider checking if a namespace already exists in the array before adding it, or use a Set to ensure uniqueness. This could happen if a user imports the same namespaces again.

Suggested change
settings.allowedNamespaces.push(...namespacesInCluster.map(it => it.namespace.name));
const allowedNamespacesSet = new Set<string>(settings.allowedNamespaces);
for (const { namespace } of namespacesInCluster) {
allowedNamespacesSet.add(namespace.name);
}
settings.allowedNamespaces = Array.from(allowedNamespacesSet);

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this can't hurt doing.

localStorage.setItem(`cluster_settings.${clusterName}`, JSON.stringify(settings));

// Step 2: Mark all namespaces in this cluster as successfully imported
// No need to patch labels - they already exist from AKS managed namespace
for (const { namespace, projectName } of namespacesInCluster) {
Expand Down
Loading