|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +This file provides guidance for AI coding agents working on this Headlamp plugin. |
| 4 | + |
| 5 | +## Available Scripts |
| 6 | + |
| 7 | +The following npm scripts are available for development and testing: |
| 8 | + |
| 9 | +- **`npm run format`** - Format code with prettier |
| 10 | +- **`npm run lint`** - Lint code with eslint for coding issues |
| 11 | +- **`npm run lint-fix`** - Automatically fix linting issues |
| 12 | +- **`npm run build`** - Build the plugin for production |
| 13 | +- **`npm run tsc`** - Type check code with TypeScript compiler |
| 14 | +- **`npm run test`** - Run tests with vitest |
| 15 | +- **`npm start`** - Start development server watching for changes |
| 16 | +- **`npm run storybook`** - Start Storybook for component development |
| 17 | +- **`npm run storybook-build`** - Build static Storybook |
| 18 | +- **`npm run i18n`** - Extract translatable strings for internationalization |
| 19 | +- **`npm run package`** - Create a tarball of the plugin package |
| 20 | + |
| 21 | +## Plugin Development Resources |
| 22 | + |
| 23 | +### Example Plugins |
| 24 | + |
| 25 | +Explore these example plugins in `node_modules/@kinvolk/headlamp-plugin/examples/` to learn common patterns: |
| 26 | + |
| 27 | +- **activity** - Shows how to add activity tracking and monitoring |
| 28 | +- **app-menus** - Demonstrates adding custom menus to the app bar |
| 29 | +- **change-logo** - Shows how to customize the Headlamp logo |
| 30 | +- **cluster-chooser** - Demonstrates cluster selection UI |
| 31 | +- **custom-theme** - Shows how to create custom themes |
| 32 | +- **customizing-map** - Demonstrates customizing resource visualization maps |
| 33 | +- **details-view** - Shows how to customize resource detail views |
| 34 | +- **dynamic-clusters** - Demonstrates dynamic cluster configuration |
| 35 | +- **headlamp-events** - Shows how to work with Kubernetes events |
| 36 | +- **pod-counter** - Simple example counting pods and displaying in app bar |
| 37 | +- **projects** - Demonstrates project/namespace organization |
| 38 | +- **resource-charts** - Shows how to add custom charts for resources |
| 39 | +- **sidebar** - Demonstrates customizing the sidebar navigation |
| 40 | +- **tables** - Shows how to create custom resource tables |
| 41 | +- **ui-panels** - Demonstrates adding custom UI panels |
| 42 | + |
| 43 | +### Official Plugins |
| 44 | + |
| 45 | +Check out production-ready plugins in `node_modules/@kinvolk/headlamp-plugin/official-plugins/` for advanced patterns: |
| 46 | + |
| 47 | +#### Using Custom Resource Definitions (CRDs) |
| 48 | + |
| 49 | +- **cert-manager** - Complete CRD integration for cert-manager resources |
| 50 | + - Files: `official-plugins/cert-manager/src/resources/` (certificate.ts, issuer.ts, clusterIssuer.ts, etc.) |
| 51 | + - Shows how to register and display custom resources for certificates, issuers, challenges, and orders |
| 52 | +- **flux** - GitOps CRDs for Flux resources |
| 53 | + - Files: `official-plugins/flux/src/` (kustomization, helmrelease, gitrepository resources) |
| 54 | + - Demonstrates working with Flux CRDs for GitOps workflows |
| 55 | +- **keda** - Kubernetes Event Driven Autoscaling CRDs |
| 56 | + - Files: `official-plugins/keda/src/resources/` (scaledobject.ts, scaledjob.ts, triggerauthentication.ts) |
| 57 | + - Shows CRD integration for event-driven autoscaling |
| 58 | +- **karpenter** - Node provisioning CRDs |
| 59 | + - Files: `official-plugins/karpenter/src/` (NodeClass, EC2NodeClass resources) |
| 60 | + - Demonstrates multiple CRD deployment types (EKS Auto Mode, self-installed) |
| 61 | + |
| 62 | +#### Visualizing Relationships with Maps |
| 63 | + |
| 64 | +- **keda** - Map view showing KEDA resource relationships |
| 65 | + - File: `official-plugins/keda/src/mapView.tsx` |
| 66 | + - Uses edge creation (`makeKubeToKubeEdge`) to visualize connections between ScaledObjects, ScaledJobs, and TriggerAuthentications |
| 67 | + - Shows how to build graph visualizations of resource dependencies |
| 68 | + |
| 69 | +#### Adding Metrics and Charts |
| 70 | + |
| 71 | +- **prometheus** - Advanced charts for workload resources |
| 72 | + - Files: `official-plugins/prometheus/src/components/Chart/` |
| 73 | + - Provides CPU, memory, network, and disk charts using Prometheus metrics |
| 74 | + - Includes specialized charts for Karpenter (KarpenterChart, KarpenterNodeClaimCreationChart) |
| 75 | + - Shows KEDA metrics (KedaActiveJobsChart, KedaScalerMetricsChart, KedaHPAReplicasChart) |
| 76 | + - File: `official-plugins/prometheus/src/request.tsx` for fetching Prometheus data |
| 77 | +- **opencost** - Cost metrics and visualization |
| 78 | + - File: `official-plugins/opencost/src/detail.tsx` |
| 79 | + - Uses `recharts` library (AreaChart, CartesianGrid, Tooltip) to display cost data |
| 80 | + - Shows how to fetch and display custom metrics from external services |
| 81 | + - Demonstrates time-series data visualization with stacked area charts |
| 82 | + |
| 83 | +#### Other Advanced Patterns |
| 84 | + |
| 85 | +- **ai-assistant** - AI integration for cluster management |
| 86 | +- **app-catalog** - Helm chart catalog powered by ArtifactHub |
| 87 | +- **backstage** - Integration with Backstage developer portal |
| 88 | + |
| 89 | +### Key Topics and Examples |
| 90 | + |
| 91 | +#### Adding Items to the App Bar |
| 92 | + |
| 93 | +- **Example:** `pod-counter` - Shows `registerAppBarAction` to add items to top bar |
| 94 | +- **File:** `examples/pod-counter/src/index.tsx` |
| 95 | + |
| 96 | +#### Customizing the Sidebar |
| 97 | + |
| 98 | +- **Example:** `sidebar` - Demonstrates `registerSidebarEntry` and `registerSidebarEntryFilter` |
| 99 | +- **File:** `examples/sidebar/src/index.tsx` |
| 100 | + |
| 101 | +#### Working with Resource Details |
| 102 | + |
| 103 | +- **Example:** `details-view` - Shows how to customize resource detail pages |
| 104 | +- **File:** `examples/details-view/src/index.tsx` |
| 105 | + |
| 106 | +#### Creating Custom Tables |
| 107 | + |
| 108 | +- **Example:** `tables` - Demonstrates custom table implementations |
| 109 | +- **File:** `examples/tables/src/index.tsx` |
| 110 | + |
| 111 | +#### Adding Charts and Visualizations |
| 112 | + |
| 113 | +- **Example:** `resource-charts` - Shows how to add custom charts |
| 114 | +- **File:** `examples/resource-charts/src/index.tsx` |
| 115 | + |
| 116 | +#### Theme Customization |
| 117 | + |
| 118 | +- **Example:** `custom-theme` - Demonstrates theme customization |
| 119 | +- **File:** `examples/custom-theme/src/index.tsx` |
| 120 | + |
| 121 | +#### Internationalization (i18n) |
| 122 | + |
| 123 | +- Use `npm run i18n <locale>` to add new locales (e.g., `npm run i18n es` for Spanish) |
| 124 | +- Translation files are in `locales/<locale>/translation.json` |
| 125 | +- Use `useTranslation()` hook from `@kinvolk/headlamp-plugin/i18n` |
| 126 | + |
| 127 | +## Development Workflow |
| 128 | + |
| 129 | +1. **Start Development:** Run `npm start` to watch for changes |
| 130 | +2. **Make Changes:** Edit files in `src/` |
| 131 | +3. **Type Check:** Run `npm run tsc` to check for TypeScript errors |
| 132 | +4. **Lint:** Run `npm run lint` to check for code quality issues |
| 133 | +5. **Format:** Run `npm run format` to format code |
| 134 | +6. **Test:** Run `npm run test` to run tests |
| 135 | +7. **Build:** Run `npm run build` to create production build |
| 136 | + |
| 137 | +## Best Practices |
| 138 | + |
| 139 | +- Follow the patterns shown in the example plugins |
| 140 | +- Use TypeScript for type safety |
| 141 | +- Keep plugins focused on a single feature or enhancement |
| 142 | +- Document your plugin's functionality in the README.md |
| 143 | + |
| 144 | +## API Documentation |
| 145 | + |
| 146 | +For detailed API documentation, visit: |
| 147 | + |
| 148 | +- [Headlamp Plugin API Reference](https://headlamp.dev/docs/latest/development/api/) |
| 149 | +- [Plugin Development Guide](https://headlamp.dev/docs/latest/development/plugins/) |
| 150 | +- [UI Component Storybook](https://headlamp.dev/docs/latest/development/frontend/#storybook) |
0 commit comments