Skip to content

feat: Add Argo CD Application detail view, Sync/Refresh via Kubernetes API#876

Open
Joshna907 wants to merge 7 commits into
headlamp-k8s:mainfrom
Joshna907:feat/argocd-detail-and-actions
Open

feat: Add Argo CD Application detail view, Sync/Refresh via Kubernetes API#876
Joshna907 wants to merge 7 commits into
headlamp-k8s:mainfrom
Joshna907:feat/argocd-detail-and-actions

Conversation

@Joshna907

Copy link
Copy Markdown
Contributor

Summary

This PR adds a detail page, Sync and Refresh actions, the official Argo CD sidebar icon, and proper route navigation. All mutations use the Kubernetes API directly — no Argo CD REST API or session tokens needed.

Why Kubernetes API instead of the Argo CD REST API?

Headlamp plugins route all API calls through the Kubernetes apiserver service proxy. This means the Argo CD REST API is unreachable from a plugin:

  • The Authorization: Bearer header is consumed by the apiserver for its own auth and never forwarded to argocd-server.
  • The Cookie header is a forbidden header — the browser strips it before the request leaves.
  • Headlamp's Electron renderer has document.cookie disabled, so cookies can't be set programmatically either.

All three auth channels fail, so the Argo CD session token can never reach argocd-server. Instead, this plugin drives Argo CD the Kubernetes-native way:

  • Sync — Patches the Application's .operation field via application/merge-patch+json. The Argo CD application-controller watches this field and runs the sync, exactly as the Argo CD CLI does.
  • Refresh — Sets the argocd.argoproj.io/refresh annotation. The controller reconciles the app against its Git source when it sees this annotation.

No Argo CD API authentication is needed — the user's existing cluster RBAC governs access. This is the same approach used by the Flux plugin (annotation patches) and Microsoft's vscode-aks-tools (kubectl-based, never REST API).

Changes

Added

  • src/components/applications/Detail.tsx — Application detail view using Headlamp's DetailsGrid. Displays project, source repo, target revision, path, destination, sync status, and health status as color-coded badges. Includes Kubernetes events via withEvents.

Changed

  • src/resources/application.ts — Added static get detailsRoute() so name links in the list view navigate to the detail page instead of falling back to Home.
  • src/index.tsx — Registered the detail route, added the official Argo CD octopus logo as an offline Iconify icon via addIcon() (CSP-safe, no external fetch), changed sidebar icon from generic mdi:application-cog to branded simple-icons:argo.
  • src/components/applications/List.tsx — Added Sync and Refresh as row actions using Headlamp's ActionButton and actions prop. Both call Kubernetes API merge-patch functions from argoClient.ts and show toast notifications via notistack on success/failure.
  • package.json — Bumped version to 0.1.1.

Screenshots

image

Steps to Test

  1. Have a running Kubernetes cluster with Argo CD installed and Headlamp accessible.
  2. Apply the mock CRD and test data if needed:
    kubectl apply -f test-files/deploy/crd.yaml

@Joshna907 Joshna907 force-pushed the feat/argocd-detail-and-actions branch from 6bb77be to 5d7ef86 Compare July 4, 2026 06:25
@illume illume requested a review from Copilot July 5, 2026 12:28

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 enhances the argocd Headlamp plugin by adding an Application detail page and list row actions (Sync/Refresh) implemented via Kubernetes API patches, plus improving navigation and branding with the official Argo CD sidebar icon.

Changes:

  • Added an Application detail view route/page and wired detailsRoute so name links navigate correctly.
  • Added Sync/Refresh row actions that patch the Application CR via the Kubernetes API (no Argo CD REST/session auth).
  • Registered the Argo CD icon for offline rendering and bumped the plugin version.

Reviewed changes

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

Show a summary per file
File Description
argocd/src/resources/application.ts Adds detailsRoute to match the registered detail route.
argocd/src/index.tsx Registers offline icon, list + detail routes, and updates sidebar icon.
argocd/src/index.test.tsx Updates mocks and assertions for new route + icon registration.
argocd/src/components/applications/List.tsx Adds Sync/Refresh actions and toast notifications for mutations.
argocd/src/components/applications/Detail.tsx New Application detail view using DetailsGrid and status badges.
argocd/src/api/argoClient.ts New Kubernetes API merge-patch helpers for sync/refresh.
argocd/package.json Version bump to 0.1.1.
argocd/package-lock.json Updates lock metadata to match the package name/version.
Files not reviewed (1)
  • argocd/package-lock.json: Generated file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread argocd/src/components/applications/List.tsx
Comment thread argocd/src/components/applications/List.tsx Outdated
Comment thread argocd/src/components/applications/Detail.tsx Outdated
Comment thread argocd/src/components/applications/Detail.tsx Outdated
Comment thread argocd/src/api/argoClient.ts Outdated
@Tatsinnit

Tatsinnit commented Jul 6, 2026

Copy link
Copy Markdown

Review Feedback

Thank you for this. I have some questions and suggestions that would help strengthen this further.

Questions & Clarifications

1. Error Handling & RBAC

  • How are RBAC permission errors communicated to users? If someone lacks applications.argoproj.io patch permissions, what message do they see?
  • What happens if sync is triggered while another sync is in progress? Does the API return an error, or is it silently queued?
  • Suggestion: Document required Kubernetes permissions somewhere (PR description, plugin README, or code comments)

2. Test Coverage

Could you clarify:

  • Are there unit tests for syncApplication() and refreshApplication() functions?
  • Do tests cover error scenarios (403 Forbidden, network timeouts, invalid Application state)?
  • A brief test coverage note in the PR would be helpful

3. Documentation

Consider updating:

  • Plugin README with the new detail view and actions
  • Required RBAC permissions for users
  • Any behavioral differences compared to using Argo CD UI directly

4. Edge Cases

  • Refresh annotation lifecycle: Does argocd.argoproj.io/refresh auto-cleanup after reconciliation, or does it need manual removal?
  • Sync operation cleanup: After sync completes, does the .operation field require cleanup, or is it controller-managed?
  • Concurrent operations: How does the system handle multiple users syncing the same application simultaneously?

5. Semantic Versioning

The bump 0.1.0 → 0.1.1 suggests a patch, but this adds significant features (detail view + actions). Consider 0.2.0 per semver conventions for new functionality.

6. UX - Loading States

Do the Sync/Refresh buttons show loading indicators during API calls? This would prevent accidental double-clicks and improve user feedback.

💡Code Suggestions

Loading State Management (List.tsx)

Consider adding explicit loading state to prevent double-clicks:

const [isSyncing, setIsSyncing] = useState<string | null>(null); // Track by app name/namespace

const handleSync = async (app: Application) => {
  const appKey = `${app.metadata.namespace}/${app.metadata.name}`;
  if (isSyncing === appKey) return; // Prevent double-click
  
  setIsSyncing(appKey);
  try {
    await syncApplication(app);
    enqueueSnackbar(`Sync initiated for ${app.metadata.name}`, { variant: 'success' });
  } catch (error) {
    enqueueSnackbar(`Sync failed: ${error.message}`, { variant: 'error' });
  } finally {
    setIsSyncing(null);
  }
};

RBAC Error Handling (argoClient.ts)

Enhance error messages for permission issues:

try {
  await apiClient.patch(/* ... */);
} catch (error) {
  if (error.statusCode === 403) {
    throw new Error(
      `Insufficient permissions to sync Application. ` +
      `Required: applications.argoproj.io [update, patch] in namespace ${namespace}`
    );
  }
  throw error;
}

✅ Recommended Before Merge

  1. Clarify test coverage for the API client functions
  2. Document RBAC requirements (in README or PR description)
  3. Consider semantic versioning question (0.1.1 vs 0.2.0)
  4. Note any known limitations (e.g., "operation status polling not implemented")

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 8 out of 9 changed files in this pull request and generated 3 comments.

Files not reviewed (1)
  • argocd/package-lock.json: Generated file

Comment thread argocd/src/components/applications/List.tsx
Comment thread argocd/src/components/applications/List.tsx
Comment thread argocd/src/components/applications/Detail.tsx Outdated
@Joshna907

Copy link
Copy Markdown
Contributor Author

ptal @illume @Tatsinnit now

@itvi-1234

itvi-1234 commented Jul 7, 2026

Copy link
Copy Markdown

I think we should take a look at the commit messages , not including fixes for previous commits in the same PR. The last couple of commits fall within that. Instead they should be added to the previous commit. This is so that when people review commit by commit they can understand it better. Otherwise they might be like "oh I spot a bug here, and here are some paragraphs explaining it"... then several commits later... "oh, they fixed it."

Joshna907 added 2 commits July 8, 2026 06:21
Add detail page using Headlamp's DetailsGrid to render standard metadata
plus Argo CD-specific fields (project, source, sync and health status).
Status columns are rendered as color-coded badges using StatusLabel.

Extract shared status-mapping functions (getHealthStatus, getSyncStatus)
into statusHelpers.ts so both the list and detail views use the same logic.

Signed-off-by: Joshna907 <joshnawaikar@gmail.com>
Add static detailsRoute getter so name links in the list view navigate
to the detail page instead of falling back to Home.

Signed-off-by: Joshna907 <joshnawaikar@gmail.com>
@Joshna907 Joshna907 force-pushed the feat/argocd-detail-and-actions branch from 2f68943 to d90a84b Compare July 8, 2026 14:42
@illume illume requested a review from Copilot July 8, 2026 20:50

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 10 out of 11 changed files in this pull request and generated 2 comments.

Files not reviewed (1)
  • argocd/package-lock.json: Generated file

Comment thread argocd/src/api/argoClient.ts
Comment thread argocd/package.json
@Joshna907 Joshna907 force-pushed the feat/argocd-detail-and-actions branch from d90a84b to 5f0f63b Compare July 9, 2026 15:30
Comment thread argocd/src/api/argoClient.ts Outdated

@ashu8912 ashu8912 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Added a few nits and comments

@Joshna907 Joshna907 force-pushed the feat/argocd-detail-and-actions branch 2 times, most recently from 503776a to c1a8e7c Compare July 10, 2026 11:00
Add merge-patch functions for sync (.operation field) and refresh
(argocd.argoproj.io/refresh annotation). Includes RBAC-aware error
handling that surfaces a user-friendly message on 403 Forbidden.

Signed-off-by: Joshna907 <joshnawaikar@gmail.com>
Register the detail route, add the official Argo CD octopus logo as an
offline Iconify icon via addIcon() (CSP-safe, no external fetch), and
change sidebar icon from generic mdi:application-cog to branded
simple-icons:argo.

Signed-off-by: Joshna907 <joshnawaikar@gmail.com>
Add Sync and Refresh as row actions using Headlamp's ActionButton and
actions prop. Both call Kubernetes API merge-patch functions from
argoClient.ts with loading state to prevent double-clicks and snackbar
notifications showing error details on failure.

Bump version to 0.2.0 for new features (semver).

Signed-off-by: Joshna907 <joshnawaikar@gmail.com>
Add unit tests for syncApplication and refreshApplication verifying
URL, method, headers, and patch body. Include error scenario tests
for 403 RBAC forbidden and network error passthrough. Update existing
index.test.tsx mocks for the detail view route.

Signed-off-by: Joshna907 <joshnawaikar@gmail.com>
Document the detail view, Sync/Refresh actions, K8s API rationale,
and required RBAC permissions (ClusterRole manifest).

Signed-off-by: Joshna907 <joshnawaikar@gmail.com>
@Joshna907

Joshna907 commented Jul 11, 2026

Copy link
Copy Markdown
Contributor Author

Added a few nits and comments

Ptal @ashu8912 @illume it is ready to get merged ig ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants