Skip to content

frontend: Warn before deleting protected namespaces - #6106

Merged
vyncent-t merged 5 commits into
kubernetes-sigs:mainfrom
Anjali-Chauhan1:fix/namespace-delete-warning
Jul 27, 2026
Merged

frontend: Warn before deleting protected namespaces#6106
vyncent-t merged 5 commits into
kubernetes-sigs:mainfrom
Anjali-Chauhan1:fix/namespace-delete-warning

Conversation

@Anjali-Chauhan1

@Anjali-Chauhan1 Anjali-Chauhan1 commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR adds a UI safeguard against accidentally deleting Kubernetes system namespaces. Headlamp previously showed Delete and Force Delete for every namespace — including default, kube-system, kube-node-lease, and kube-public — so a user with a cluster-admin token could break a cluster with a single accidental click. These namespaces are now treated as protected: the delete dialog shows a warning and requires typing the namespace name to confirm.

Related Issue

Fixes #6064

Changes

  • Added Namespace.PROTECTED_NAMESPACES and an isProtected() helper in lib/k8s/namespace.ts, matched against the kubernetes.io/metadata.name label (falling back to the object name).
  • Updated DeleteButton to show a warning Alert and a type-the-name confirmation field, keeping the Delete button disabled until the name matches, for protected namespaces.
  • Updated DeleteMultipleButton to flag any protected namespaces in a multi-select deletion.
  • Minor ConfirmDialog change to support the disabled-confirm state.
  • Fixed dark-theme contrast so the warning text/border is readable (warning Alert previously rendered near-invisible in dark mode).
  • Added unit tests for isProtected() and interactive Storybook stories (ProtectedNamespace, NonProtectedNamespace). These use a play interaction to open the confirm dialog, so storyshots are disabled for them (same as other play-based stories in the repo).
  • Added the new i18n string to the translation catalogs.

Steps to Test

  1. Open a cluster and navigate to Namespaces.
  2. Click delete on a system namespace (e.g. kube-system). Observe the warning "This is a system namespace. Deleting it may break your cluster." and that Delete stays disabled until you type the namespace name.
  3. Click delete on a regular namespace (e.g. my-app). Observe the standard single-confirmation flow with no warning.
  4. Multi-select several namespaces including a system one and delete. Observe the warning that the selection includes system namespaces.
  5. Switch to dark theme and repeat step 2 — confirm the warning box and text are clearly visible.

Screenshots

Screenshot 2026-06-19 202318

Screenshot 2026-06-19 202301

Notes for the Reviewer

  • Protection is purely a UI guard / first line of defense; the API server is still the source of truth.
  • This touches the i18n layer — only the English string is filled in; the other locale catalogs get the empty key for translators.
  • The dark-theme fix is applied per-component (explicit warning.mainon the Alert) rather than changing the shared theme, because palette.warning.light is intentionally reused as a translucent background tint elsewhere (PluginSettingsDetails).

@k8s-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Anjali-Chauhan1
Once this PR has been reviewed and has the lgtm label, please assign joaquimrocha for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot
k8s-ci-robot requested review from sniok and yolossn June 19, 2026 20:05
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jun 19, 2026

@mahesh-09-12 mahesh-09-12 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@Anjali-Chauhan1 took a look at the namespace safeguards and the changes around deletion behavior. The checks added here appear consistent with the expected restrictions, and the confirmation prompt is applied appropriately across the affected actions. I didn't spot any issues in the code paths modified by this update.

@Anjali-Chauhan1

Copy link
Copy Markdown
Contributor Author

@illume , plz review the pr.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a frontend safety guard to reduce accidental deletion of Kubernetes system namespaces by introducing a “protected namespace” concept and requiring an explicit type-to-confirm step in the delete confirmation UI.

Changes:

  • Add Namespace.PROTECTED_NAMESPACES and Namespace.isProtected() helper for identifying system namespaces.
  • Update single and multi-delete dialogs to warn on protected namespaces and disable Confirm until the required name(s) are typed.
  • Add i18n keys for the new UI strings plus unit tests and Storybook stories/snapshots.

Reviewed changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
frontend/src/lib/k8s/namespace.ts Adds protected namespace list and isProtected() helper.
frontend/src/lib/k8s/index.test.ts Adds unit tests covering Namespace.isProtected().
frontend/src/components/common/ConfirmDialog.tsx Adds confirmButtonDisabled prop to support disabled confirm state.
frontend/src/components/common/Resource/DeleteButton.tsx Adds protected-namespace warning and type-to-confirm gating for single delete.
frontend/src/components/common/Resource/DeleteMultipleButton.tsx Adds protected-namespace warning and type-to-confirm gating for multi delete.
frontend/src/components/common/Resource/DeleteButton.stories.tsx Adds protected/non-protected namespace stories.
frontend/src/components/common/Resource/snapshots/DeleteButton.ProtectedNamespace.stories.storyshot Adds snapshot for the new protected namespace story.
frontend/src/components/common/Resource/snapshots/DeleteButton.NonProtectedNamespace.stories.storyshot Adds snapshot for the new non-protected namespace story.
frontend/src/i18n/locales/en/translation.json Adds English strings for protected-namespace warnings and prompts.
frontend/src/i18n/locales/ar/translation.json Adds empty-string placeholders for new keys (translation fallback behavior).
frontend/src/i18n/locales/bn/translation.json Adds empty-string placeholders for new keys (translation fallback behavior).
frontend/src/i18n/locales/de/translation.json Adds empty-string placeholders for new keys (translation fallback behavior).
frontend/src/i18n/locales/es/translation.json Adds empty-string placeholders for new keys (translation fallback behavior).
frontend/src/i18n/locales/fr/translation.json Adds empty-string placeholders for new keys (translation fallback behavior).
frontend/src/i18n/locales/he/translation.json Adds empty-string placeholders for new keys (translation fallback behavior).
frontend/src/i18n/locales/hi/translation.json Adds empty-string placeholders for new keys (translation fallback behavior).
frontend/src/i18n/locales/it/translation.json Adds empty-string placeholders for new keys (translation fallback behavior).
frontend/src/i18n/locales/ja/translation.json Adds empty-string placeholders for new keys (translation fallback behavior).
frontend/src/i18n/locales/ko/translation.json Adds empty-string placeholders for new keys (translation fallback behavior).
frontend/src/i18n/locales/pt/translation.json Adds empty-string placeholders for new keys (translation fallback behavior).
frontend/src/i18n/locales/ru/translation.json Adds empty-string placeholders for new keys (translation fallback behavior).
frontend/src/i18n/locales/ta/translation.json Adds empty-string placeholders for new keys (translation fallback behavior).
frontend/src/i18n/locales/ur/translation.json Adds empty-string placeholders for new keys (translation fallback behavior).
frontend/src/i18n/locales/zh/translation.json Adds empty-string placeholders for new keys (translation fallback behavior).
frontend/src/i18n/locales/zh-tw/translation.json Adds empty-string placeholders for new keys (translation fallback behavior).

Comment thread frontend/src/components/common/Resource/DeleteMultipleButton.tsx Outdated
Comment thread frontend/src/components/common/Resource/DeleteButton.tsx
@Anjali-Chauhan1
Anjali-Chauhan1 force-pushed the fix/namespace-delete-warning branch from 9022d0b to 222ea7b Compare June 23, 2026 09:19
@Anjali-Chauhan1

Copy link
Copy Markdown
Contributor Author

@illume, I have did the required changes that are suggested by copilot :)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 25 out of 25 changed files in this pull request and generated 3 comments.

Comment thread frontend/src/components/common/Resource/DeleteMultipleButton.tsx Outdated
Comment thread frontend/src/components/common/Resource/DeleteButton.tsx Outdated
Comment thread frontend/src/components/common/Resource/DeleteButton.stories.tsx
@Anjali-Chauhan1
Anjali-Chauhan1 force-pushed the fix/namespace-delete-warning branch from 222ea7b to e53d819 Compare June 23, 2026 18:41
@kubernetes-prow kubernetes-prow Bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 23, 2026
@illume
illume requested a review from Copilot June 24, 2026 13:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 26 out of 26 changed files in this pull request and generated 5 comments.

Comment thread frontend/src/components/common/Resource/DeleteButton.test.tsx
Comment thread frontend/src/components/common/Resource/DeleteButton.test.tsx
Comment thread frontend/src/components/common/Resource/DeleteButton.tsx Outdated
Comment thread frontend/src/components/common/Resource/DeleteMultipleButton.tsx
Comment thread frontend/src/components/common/Resource/DeleteMultipleButton.tsx

@illume illume left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for these changes.

Can you please address the open review comments? Once you've resolved each one, please mark it as resolved.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 27 out of 27 changed files in this pull request and generated 1 comment.

Comment thread frontend/src/components/common/Resource/DeleteButton.stories.tsx Outdated
@illume
illume requested a review from Copilot June 26, 2026 09:09

@illume illume left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the contribution.

Could you take a look at the commit messages in this PR? We follow a Linux kernel style for git commits — see the contributing guide and git log for examples.

Commits that need attention
  • frontend: Remove comment from DeleteButton stories — Only one file changed inside frontend/; add a sub-area so it's clear what was touched (e.g. frontend: ComponentName: description).
Commit guidelines
  • Use atomic commits focused on a single change.
  • Use the title format <area>: <Description of changes> — description must start with a capital letter.
  • Keep the title under 72 characters (soft requirement).
  • Explain the intention and why the change is needed.
  • Make commit titles meaningful and describe what changed.
  • Do not add code that a later commit rewrites; squash or reorder commits instead.
  • Do not include Fixes #NN in commit messages.

Good examples:

  • frontend: HomeButton: Fix so it navigates to home
  • backend: config: Add enable-dynamic-clusters flag

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 27 out of 27 changed files in this pull request and generated 2 comments.

Comment thread frontend/src/components/common/Resource/DeleteButton.stories.tsx
Comment thread frontend/src/components/common/ConfirmDialog.tsx

@illume illume left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for these changes.

Can you please address the open review comments? Once you've resolved each one, please mark it as resolved.

Signed-off-by: Anjali-Chauhan1 <anjalichauhan1036@gmail.com>

frontend: Update namespace deletion confirmation

frontend: Add DeleteButton tests and refine protected namespace confirmation

Signed-off-by: Anjali-Chauhan1 <anjalichauhan1036@gmail.com>

frontend: Protect namespace deletion checks

Signed-off-by: Anjali-Chauhan1 <anjalichauhan1036@gmail.com>

frontend: DeleteButton.stories: Remove unnecessary comments

Signed-off-by: Anjali-Chauhan1 <anjalichauhan1036@gmail.com>
Signed-off-by: Anjali-Chauhan1 <anjalichauhan1036@gmail.com>
Signed-off-by: Anjali-Chauhan1 <anjalichauhan1036@gmail.com>

refactor: Simplify protected namespace checks

Signed-off-by: Anjali-Chauhan1 <anjalichauhan1036@gmail.com>
Signed-off-by: Anjali-Chauhan1 <anjalichauhan1036@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 27 out of 27 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (2)

frontend/src/components/common/Resource/DeleteButton.tsx:102

  • isProtectedNamespace currently relies on a cast and namespaceName uses ??. If a Namespace object is not an actual Namespace instance (or if the kubernetes.io/metadata.name label exists but is an empty string), this can throw or unintentionally enable deletion without typing anything. Use Namespace.isClassOf(item) for a safe type guard and use || so empty-string labels don’t bypass the type-to-confirm step.
  // System namespaces require an extra type-to-confirm step before they can be deleted.
  const isProtectedNamespace = item.kind === 'Namespace' && (item as Namespace).isProtected();
  // Use the same label-or-name value that isProtected() checks so the confirmation prompt matches.
  const namespaceName = item.metadata.labels?.['kubernetes.io/metadata.name'] ?? item.metadata.name;

frontend/src/components/common/Resource/DeleteMultipleButton.tsx:84

  • protectedNamespaces uses a kind-string check plus a cast to call isProtected(). This is less safe than the established pattern in the codebase (e.g. Deployment.isClassOf(item) in ScaleMultipleButton.tsx) and can crash if an item has kind Namespace but isn’t an actual Namespace instance. Prefer Namespace.isClassOf(item) as the type guard before calling item.isProtected().
  // Protected namespaces included in the current selection, if any.
  const protectedNamespaces = (items ?? []).filter(
    (item): item is Namespace => item.kind === 'Namespace' && (item as Namespace).isProtected()
  );

Comment thread frontend/src/lib/k8s/namespace.ts Outdated
Comment thread frontend/src/components/common/Resource/DeleteMultipleButton.tsx
Signed-off-by: Anjali-Chauhan1 <anjalichauhan1036@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 27 out of 27 changed files in this pull request and generated 1 comment.

Comment thread frontend/src/components/common/Resource/DeleteButton.stories.tsx

@illume illume left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for these changes.

Can you please address the open review comments? Once you've resolved each one, please mark it as resolved.

@Anjali-Chauhan1
Anjali-Chauhan1 requested a review from illume July 25, 2026 01:27
@illume illume added collab Collaborative work across contributors frontend Issues related to the frontend testing labels Jul 25, 2026
@illume illume added this to the v0.44.0 milestone Jul 27, 2026

@vyncent-t vyncent-t left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

tested LGTM

@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Anjali-Chauhan1, vyncent-t

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubernetes-prow kubernetes-prow Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 27, 2026
@vyncent-t
vyncent-t merged commit 6e57934 into kubernetes-sigs:main Jul 27, 2026
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. collab Collaborative work across contributors frontend Issues related to the frontend size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hide or warn before deleting system namespaces in UI

6 participants