@vfarcic/dot-ai 0.5.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/{src/cli.ts → dist/cli.js} +19 -26
- package/dist/core/claude.d.ts +42 -0
- package/dist/core/claude.d.ts.map +1 -0
- package/dist/core/claude.js +229 -0
- package/dist/core/deploy-operation.d.ts +38 -0
- package/dist/core/deploy-operation.d.ts.map +1 -0
- package/dist/core/deploy-operation.js +101 -0
- package/dist/core/discovery.d.ts +162 -0
- package/dist/core/discovery.d.ts.map +1 -0
- package/dist/core/discovery.js +758 -0
- package/dist/core/error-handling.d.ts +167 -0
- package/dist/core/error-handling.d.ts.map +1 -0
- package/dist/core/error-handling.js +399 -0
- package/dist/core/index.d.ts +42 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +123 -0
- package/dist/core/kubernetes-utils.d.ts +38 -0
- package/dist/core/kubernetes-utils.d.ts.map +1 -0
- package/dist/core/kubernetes-utils.js +177 -0
- package/dist/core/memory.d.ts +45 -0
- package/dist/core/memory.d.ts.map +1 -0
- package/dist/core/memory.js +113 -0
- package/dist/core/schema.d.ts +187 -0
- package/dist/core/schema.d.ts.map +1 -0
- package/dist/core/schema.js +655 -0
- package/dist/core/session-utils.d.ts +29 -0
- package/dist/core/session-utils.d.ts.map +1 -0
- package/dist/core/session-utils.js +121 -0
- package/dist/core/workflow.d.ts +70 -0
- package/dist/core/workflow.d.ts.map +1 -0
- package/dist/core/workflow.js +161 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/interfaces/cli.d.ts +74 -0
- package/dist/interfaces/cli.d.ts.map +1 -0
- package/dist/interfaces/cli.js +769 -0
- package/dist/interfaces/mcp.d.ts +30 -0
- package/dist/interfaces/mcp.d.ts.map +1 -0
- package/dist/interfaces/mcp.js +105 -0
- package/dist/mcp/server.d.ts +9 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +151 -0
- package/dist/tools/answer-question.d.ts +27 -0
- package/dist/tools/answer-question.d.ts.map +1 -0
- package/dist/tools/answer-question.js +696 -0
- package/dist/tools/choose-solution.d.ts +23 -0
- package/dist/tools/choose-solution.d.ts.map +1 -0
- package/dist/tools/choose-solution.js +171 -0
- package/dist/tools/deploy-manifests.d.ts +25 -0
- package/dist/tools/deploy-manifests.d.ts.map +1 -0
- package/dist/tools/deploy-manifests.js +74 -0
- package/dist/tools/generate-manifests.d.ts +23 -0
- package/dist/tools/generate-manifests.d.ts.map +1 -0
- package/dist/tools/generate-manifests.js +424 -0
- package/dist/tools/index.d.ts +11 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +34 -0
- package/dist/tools/recommend.d.ts +23 -0
- package/dist/tools/recommend.d.ts.map +1 -0
- package/dist/tools/recommend.js +332 -0
- package/package.json +124 -2
- package/.claude/commands/context-load.md +0 -11
- package/.claude/commands/context-save.md +0 -16
- package/.claude/commands/prd-done.md +0 -115
- package/.claude/commands/prd-get.md +0 -25
- package/.claude/commands/prd-start.md +0 -87
- package/.claude/commands/task-done.md +0 -77
- package/.claude/commands/tests-reminder.md +0 -32
- package/.claude/settings.local.json +0 -20
- package/.eslintrc.json +0 -25
- package/.github/workflows/ci.yml +0 -170
- package/.prettierrc.json +0 -10
- package/.teller.yml +0 -8
- package/CLAUDE.md +0 -162
- package/assets/images/logo.png +0 -0
- package/bin/dot-ai.ts +0 -47
- package/bin.js +0 -19
- package/destroy.sh +0 -45
- package/devbox.json +0 -13
- package/devbox.lock +0 -225
- package/docs/API.md +0 -449
- package/docs/CONTEXT.md +0 -49
- package/docs/DEVELOPMENT.md +0 -203
- package/docs/NEXT_STEPS.md +0 -97
- package/docs/STAGE_BASED_API.md +0 -97
- package/docs/cli-guide.md +0 -798
- package/docs/design.md +0 -750
- package/docs/discovery-engine.md +0 -515
- package/docs/error-handling.md +0 -429
- package/docs/function-registration.md +0 -157
- package/docs/mcp-guide.md +0 -416
- package/renovate.json +0 -51
- package/setup.sh +0 -111
- package/src/core/claude.ts +0 -280
- package/src/core/deploy-operation.ts +0 -127
- package/src/core/discovery.ts +0 -900
- package/src/core/error-handling.ts +0 -562
- package/src/core/index.ts +0 -143
- package/src/core/kubernetes-utils.ts +0 -218
- package/src/core/memory.ts +0 -148
- package/src/core/schema.ts +0 -830
- package/src/core/session-utils.ts +0 -97
- package/src/core/workflow.ts +0 -234
- package/src/index.ts +0 -18
- package/src/interfaces/cli.ts +0 -872
- package/src/interfaces/mcp.ts +0 -183
- package/src/mcp/server.ts +0 -131
- package/src/tools/answer-question.ts +0 -807
- package/src/tools/choose-solution.ts +0 -169
- package/src/tools/deploy-manifests.ts +0 -94
- package/src/tools/generate-manifests.ts +0 -502
- package/src/tools/index.ts +0 -41
- package/src/tools/recommend.ts +0 -370
- package/tests/__mocks__/@kubernetes/client-node.ts +0 -106
- package/tests/build-system.test.ts +0 -345
- package/tests/configuration.test.ts +0 -226
- package/tests/core/deploy-operation.test.ts +0 -38
- package/tests/core/discovery.test.ts +0 -1648
- package/tests/core/error-handling.test.ts +0 -632
- package/tests/core/schema.test.ts +0 -1658
- package/tests/core/session-utils.test.ts +0 -245
- package/tests/core.test.ts +0 -439
- package/tests/fixtures/configmap-no-labels.yaml +0 -8
- package/tests/fixtures/crossplane-app-configuration.yaml +0 -6
- package/tests/fixtures/crossplane-providers.yaml +0 -45
- package/tests/fixtures/crossplane-rbac.yaml +0 -48
- package/tests/fixtures/invalid-configmap.yaml +0 -8
- package/tests/fixtures/invalid-deployment.yaml +0 -17
- package/tests/fixtures/test-deployment.yaml +0 -28
- package/tests/fixtures/valid-configmap.yaml +0 -15
- package/tests/infrastructure.test.ts +0 -426
- package/tests/interfaces/cli.test.ts +0 -1036
- package/tests/interfaces/mcp.test.ts +0 -139
- package/tests/kubernetes-utils.test.ts +0 -200
- package/tests/mcp/server.test.ts +0 -126
- package/tests/setup.ts +0 -31
- package/tests/tools/answer-question.test.ts +0 -367
- package/tests/tools/choose-solution.test.ts +0 -481
- package/tests/tools/deploy-manifests.test.ts +0 -185
- package/tests/tools/generate-manifests.test.ts +0 -441
- package/tests/tools/index.test.ts +0 -111
- package/tests/tools/recommend.test.ts +0 -180
- package/tsconfig.json +0 -34
package/docs/discovery-engine.md
DELETED
|
@@ -1,515 +0,0 @@
|
|
|
1
|
-
# Kubernetes Discovery Engine Documentation
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
The Kubernetes Discovery Engine provides comprehensive, unfiltered discovery capabilities for Kubernetes clusters. It exposes detailed information about API resources, Custom Resource Definitions (CRDs), cluster capabilities, and resource schemas without arbitrary filtering, enabling higher-level components to make intelligent decisions based on complete cluster information.
|
|
6
|
-
|
|
7
|
-
## Core Philosophy
|
|
8
|
-
|
|
9
|
-
The discovery engine follows these principles:
|
|
10
|
-
- **Comprehensive Discovery**: Returns all available information without filtering
|
|
11
|
-
- **Structured Data**: Provides well-defined interfaces for all discovery data
|
|
12
|
-
- **Graceful Degradation**: Continues operation when some APIs are unavailable
|
|
13
|
-
- **Enhanced Error Handling**: Provides actionable error messages with troubleshooting guidance
|
|
14
|
-
|
|
15
|
-
## Data Structures
|
|
16
|
-
|
|
17
|
-
### EnhancedResource
|
|
18
|
-
|
|
19
|
-
Represents a standard Kubernetes API resource with comprehensive metadata for resource selection and usage.
|
|
20
|
-
|
|
21
|
-
```typescript
|
|
22
|
-
interface EnhancedResource {
|
|
23
|
-
name: string; // Resource name (e.g., "pods", "services")
|
|
24
|
-
namespaced: boolean; // Whether the resource is namespace-scoped
|
|
25
|
-
kind: string; // Resource kind (e.g., "Pod", "Service")
|
|
26
|
-
shortNames: string[]; // Kubectl short names (e.g., ["po"] for pods)
|
|
27
|
-
apiVersion: string; // API version (e.g., "v1", "apps/v1")
|
|
28
|
-
group: string; // API group (empty string for core resources)
|
|
29
|
-
}
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
**Usage Examples:**
|
|
33
|
-
```typescript
|
|
34
|
-
// Filter namespaced resources for application deployment
|
|
35
|
-
const namespacedResources = resources.filter(r => r.namespaced);
|
|
36
|
-
|
|
37
|
-
// Find resources by kind
|
|
38
|
-
const deployments = resources.find(r => r.kind === 'Deployment');
|
|
39
|
-
|
|
40
|
-
// Group resources by API group
|
|
41
|
-
const byGroup = resources.reduce((acc, r) => {
|
|
42
|
-
const group = r.group || 'core';
|
|
43
|
-
if (!acc[group]) acc[group] = [];
|
|
44
|
-
acc[group].push(r);
|
|
45
|
-
return acc;
|
|
46
|
-
}, {});
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
### EnhancedCRD
|
|
50
|
-
|
|
51
|
-
Represents Custom Resource Definitions with complete version and schema information.
|
|
52
|
-
|
|
53
|
-
```typescript
|
|
54
|
-
interface EnhancedCRD {
|
|
55
|
-
name: string; // CRD name (e.g., "virtualservices.networking.istio.io")
|
|
56
|
-
group: string; // API group (e.g., "networking.istio.io")
|
|
57
|
-
version: string; // Current version (e.g., "v1beta1")
|
|
58
|
-
kind: string; // Resource kind (e.g., "VirtualService")
|
|
59
|
-
scope: 'Namespaced' | 'Cluster'; // Resource scope
|
|
60
|
-
versions: Array<{ // All available versions
|
|
61
|
-
name: string; // Version name (e.g., "v1beta1")
|
|
62
|
-
served: boolean; // Whether this version is served
|
|
63
|
-
storage: boolean; // Whether this is the storage version
|
|
64
|
-
schema?: any; // OpenAPI v3 schema (if available)
|
|
65
|
-
}>;
|
|
66
|
-
schema?: any; // Primary schema (usually from storage version)
|
|
67
|
-
}
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
**Usage Examples:**
|
|
71
|
-
```typescript
|
|
72
|
-
// Find CRDs by operator/vendor
|
|
73
|
-
const istioCRDs = crds.filter(crd => crd.group.includes('istio.io'));
|
|
74
|
-
|
|
75
|
-
// Check for specific capabilities
|
|
76
|
-
const hasVirtualServices = crds.some(crd => crd.kind === 'VirtualService');
|
|
77
|
-
|
|
78
|
-
// Get all served versions
|
|
79
|
-
const servedVersions = crd.versions.filter(v => v.served).map(v => v.name);
|
|
80
|
-
|
|
81
|
-
// Identify cluster-scoped custom resources
|
|
82
|
-
const clusterScopedCRDs = crds.filter(crd => crd.scope === 'Cluster');
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
### ResourceExplanation
|
|
86
|
-
|
|
87
|
-
Provides detailed schema information for any Kubernetes resource, parsed from `kubectl explain` output.
|
|
88
|
-
|
|
89
|
-
```typescript
|
|
90
|
-
interface ResourceExplanation {
|
|
91
|
-
kind: string; // Resource kind (e.g., "Pod")
|
|
92
|
-
version: string; // API version (e.g., "v1")
|
|
93
|
-
group: string; // API group (empty for core resources)
|
|
94
|
-
description: string; // Resource description
|
|
95
|
-
fields: Array<{ // All available fields
|
|
96
|
-
name: string; // Field name (e.g., "metadata.name")
|
|
97
|
-
type: string; // Field type (e.g., "string", "Object")
|
|
98
|
-
description: string; // Field description
|
|
99
|
-
required: boolean; // Whether field is required
|
|
100
|
-
}>;
|
|
101
|
-
}
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
**Usage Examples:**
|
|
105
|
-
```typescript
|
|
106
|
-
// Find required fields for resource creation
|
|
107
|
-
const requiredFields = explanation.fields.filter(f => f.required);
|
|
108
|
-
|
|
109
|
-
// Build field documentation
|
|
110
|
-
const fieldDocs = explanation.fields.map(f => ({
|
|
111
|
-
path: f.name,
|
|
112
|
-
type: f.type,
|
|
113
|
-
description: f.description,
|
|
114
|
-
required: f.required
|
|
115
|
-
}));
|
|
116
|
-
|
|
117
|
-
// Check for specific field availability
|
|
118
|
-
const hasSecurityContext = explanation.fields.some(f =>
|
|
119
|
-
f.name.includes('securityContext')
|
|
120
|
-
);
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
### ClusterFingerprint
|
|
124
|
-
|
|
125
|
-
Comprehensive cluster information including capabilities, features, and configuration.
|
|
126
|
-
|
|
127
|
-
```typescript
|
|
128
|
-
interface ClusterFingerprint {
|
|
129
|
-
version: string; // Kubernetes version
|
|
130
|
-
platform: string; // Platform type (e.g., "kind", "eks", "gke")
|
|
131
|
-
nodeCount: number; // Number of nodes
|
|
132
|
-
namespaceCount: number;// Number of namespaces
|
|
133
|
-
crdCount: number; // Number of CRDs installed
|
|
134
|
-
capabilities: string[];// Detected capabilities (e.g., ["api-server", "scheduler"])
|
|
135
|
-
|
|
136
|
-
features: { // Resource counts
|
|
137
|
-
deployments: number;
|
|
138
|
-
services: number;
|
|
139
|
-
pods: number;
|
|
140
|
-
configMaps: number;
|
|
141
|
-
secrets: number;
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
networking: { // Network configuration
|
|
145
|
-
cni: string; // CNI plugin
|
|
146
|
-
serviceSubnet: string;
|
|
147
|
-
podSubnet: string;
|
|
148
|
-
dnsProvider: string;
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
security: { // Security features
|
|
152
|
-
rbacEnabled: boolean;
|
|
153
|
-
podSecurityPolicy: boolean;
|
|
154
|
-
networkPolicies: boolean;
|
|
155
|
-
admissionControllers: string[];
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
storage: { // Storage capabilities
|
|
159
|
-
storageClasses: string[];
|
|
160
|
-
persistentVolumes: number;
|
|
161
|
-
csiDrivers: string[];
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
**Usage Examples:**
|
|
167
|
-
```typescript
|
|
168
|
-
// Check cluster readiness for production workloads
|
|
169
|
-
const isProductionReady = fingerprint.security.rbacEnabled &&
|
|
170
|
-
fingerprint.networking.cni !== 'unknown' &&
|
|
171
|
-
fingerprint.storage.storageClasses.length > 0;
|
|
172
|
-
|
|
173
|
-
// Determine deployment strategies based on cluster size
|
|
174
|
-
const deploymentStrategy = fingerprint.nodeCount > 3 ? 'RollingUpdate' : 'Recreate';
|
|
175
|
-
|
|
176
|
-
// Check for specific capabilities
|
|
177
|
-
const hasAutoscaling = fingerprint.capabilities.includes('horizontal-pod-autoscaler');
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
### ResourceMap
|
|
181
|
-
|
|
182
|
-
Container for all discovered resources, separating standard and custom resources.
|
|
183
|
-
|
|
184
|
-
```typescript
|
|
185
|
-
interface ResourceMap {
|
|
186
|
-
resources: EnhancedResource[]; // Standard Kubernetes resources
|
|
187
|
-
custom: EnhancedCRD[]; // Custom Resource Definitions
|
|
188
|
-
}
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
## Core Discovery Methods
|
|
192
|
-
|
|
193
|
-
### Resource Discovery
|
|
194
|
-
|
|
195
|
-
```typescript
|
|
196
|
-
// Discover all available resources (standard + custom)
|
|
197
|
-
const resourceMap = await discovery.discoverResources();
|
|
198
|
-
console.log(`Found ${resourceMap.resources.length} standard resources`);
|
|
199
|
-
console.log(`Found ${resourceMap.custom.length} custom resources`);
|
|
200
|
-
|
|
201
|
-
// Get just standard API resources
|
|
202
|
-
const apiResources = await discovery.getAPIResources();
|
|
203
|
-
const coreResources = apiResources.filter(r => r.group === '');
|
|
204
|
-
const appResources = apiResources.filter(r => r.group === 'apps');
|
|
205
|
-
|
|
206
|
-
// Get just CRDs
|
|
207
|
-
const crds = await discovery.discoverCRDs();
|
|
208
|
-
const namespacedCRDs = crds.filter(crd => crd.scope === 'Namespaced');
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
### Schema Discovery
|
|
212
|
-
|
|
213
|
-
```typescript
|
|
214
|
-
// Get detailed schema for any resource
|
|
215
|
-
const podExplanation = await discovery.explainResource('Pod');
|
|
216
|
-
console.log(`Pod has ${podExplanation.fields.length} fields`);
|
|
217
|
-
|
|
218
|
-
// Get schema for specific field
|
|
219
|
-
const metadataExplanation = await discovery.explainResource('Pod', { field: 'metadata' });
|
|
220
|
-
|
|
221
|
-
// Get schema for custom resources
|
|
222
|
-
const customExplanation = await discovery.explainResource('VirtualService');
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
### Cluster Analysis
|
|
226
|
-
|
|
227
|
-
```typescript
|
|
228
|
-
// Get comprehensive cluster information
|
|
229
|
-
const fingerprint = await discovery.fingerprintCluster();
|
|
230
|
-
|
|
231
|
-
// Basic cluster info
|
|
232
|
-
const clusterInfo = await discovery.getClusterInfo();
|
|
233
|
-
console.log(`Cluster type: ${clusterInfo.type}, version: ${clusterInfo.version}`);
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
## Integration Patterns
|
|
237
|
-
|
|
238
|
-
### CLI Integration
|
|
239
|
-
|
|
240
|
-
The CLI should consume discovery data to provide intelligent resource selection and validation:
|
|
241
|
-
|
|
242
|
-
```typescript
|
|
243
|
-
// Resource listing with grouping
|
|
244
|
-
async function listResources(options: { group?: string, namespaced?: boolean }) {
|
|
245
|
-
const resources = await discovery.getAPIResources();
|
|
246
|
-
|
|
247
|
-
let filtered = resources;
|
|
248
|
-
if (options.group) {
|
|
249
|
-
filtered = filtered.filter(r => r.group === options.group);
|
|
250
|
-
}
|
|
251
|
-
if (options.namespaced !== undefined) {
|
|
252
|
-
filtered = filtered.filter(r => r.namespaced === options.namespaced);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// Group by API group for display
|
|
256
|
-
const grouped = filtered.reduce((acc, r) => {
|
|
257
|
-
const group = r.group || 'core';
|
|
258
|
-
if (!acc[group]) acc[group] = [];
|
|
259
|
-
acc[group].push(r);
|
|
260
|
-
return acc;
|
|
261
|
-
}, {});
|
|
262
|
-
|
|
263
|
-
return grouped;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
// Resource validation before operations
|
|
267
|
-
async function validateResourceExists(kind: string): Promise<boolean> {
|
|
268
|
-
const resources = await discovery.getAPIResources();
|
|
269
|
-
return resources.some(r => r.kind === kind);
|
|
270
|
-
}
|
|
271
|
-
```
|
|
272
|
-
|
|
273
|
-
### Workflow Engine Integration
|
|
274
|
-
|
|
275
|
-
The workflow engine should use discovery data for intelligent application construction:
|
|
276
|
-
|
|
277
|
-
```typescript
|
|
278
|
-
// Capability-based workflow selection
|
|
279
|
-
async function selectWorkflow(requirements: AppRequirements): Promise<WorkflowPlan> {
|
|
280
|
-
const fingerprint = await discovery.fingerprintCluster();
|
|
281
|
-
const resources = await discovery.getAPIResources();
|
|
282
|
-
|
|
283
|
-
const plan: WorkflowPlan = {
|
|
284
|
-
steps: [],
|
|
285
|
-
requirements: [],
|
|
286
|
-
warnings: []
|
|
287
|
-
};
|
|
288
|
-
|
|
289
|
-
// Check for required capabilities
|
|
290
|
-
if (requirements.needsIngress) {
|
|
291
|
-
const hasIngressController = fingerprint.capabilities.includes('ingress-controller');
|
|
292
|
-
if (!hasIngressController) {
|
|
293
|
-
plan.warnings.push('No ingress controller detected - external access may not work');
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
// Select appropriate resource types
|
|
298
|
-
if (requirements.needsStatefulStorage) {
|
|
299
|
-
const hasStatefulSets = resources.some(r => r.kind === 'StatefulSet');
|
|
300
|
-
if (hasStatefulSets) {
|
|
301
|
-
plan.steps.push({ type: 'create-statefulset', resource: 'StatefulSet' });
|
|
302
|
-
} else {
|
|
303
|
-
plan.steps.push({ type: 'create-deployment', resource: 'Deployment' });
|
|
304
|
-
plan.warnings.push('StatefulSet not available - using Deployment instead');
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
return plan;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
// Custom resource integration
|
|
312
|
-
async function checkOperatorSupport(operatorType: string): Promise<OperatorInfo> {
|
|
313
|
-
const crds = await discovery.discoverCRDs();
|
|
314
|
-
|
|
315
|
-
const operatorCRDs = crds.filter(crd =>
|
|
316
|
-
crd.group.includes(operatorType) ||
|
|
317
|
-
crd.kind.toLowerCase().includes(operatorType)
|
|
318
|
-
);
|
|
319
|
-
|
|
320
|
-
return {
|
|
321
|
-
available: operatorCRDs.length > 0,
|
|
322
|
-
crds: operatorCRDs,
|
|
323
|
-
capabilities: operatorCRDs.map(crd => crd.kind)
|
|
324
|
-
};
|
|
325
|
-
}
|
|
326
|
-
```
|
|
327
|
-
|
|
328
|
-
### Error Handling Integration
|
|
329
|
-
|
|
330
|
-
The discovery engine provides enhanced error classification for better user experience:
|
|
331
|
-
|
|
332
|
-
```typescript
|
|
333
|
-
try {
|
|
334
|
-
await discovery.connect();
|
|
335
|
-
const resources = await discovery.discoverResources();
|
|
336
|
-
} catch (error) {
|
|
337
|
-
// Error messages are already enhanced with troubleshooting guidance
|
|
338
|
-
console.error('Discovery failed:', error.message);
|
|
339
|
-
|
|
340
|
-
// Error messages include specific commands like:
|
|
341
|
-
// "Check cluster endpoint in kubeconfig: kubectl config view"
|
|
342
|
-
// "Verify authentication: kubectl auth whoami"
|
|
343
|
-
// "Check RBAC permissions: kubectl auth can-i list pods"
|
|
344
|
-
}
|
|
345
|
-
```
|
|
346
|
-
|
|
347
|
-
## Best Practices
|
|
348
|
-
|
|
349
|
-
### 1. Cache Discovery Results
|
|
350
|
-
|
|
351
|
-
Discovery operations can be expensive, especially for large clusters:
|
|
352
|
-
|
|
353
|
-
```typescript
|
|
354
|
-
class CachedDiscovery {
|
|
355
|
-
private cache = new Map<string, { data: any; timestamp: number }>();
|
|
356
|
-
private ttl = 5 * 60 * 1000; // 5 minutes
|
|
357
|
-
|
|
358
|
-
async getResources(): Promise<EnhancedResource[]> {
|
|
359
|
-
const key = 'api-resources';
|
|
360
|
-
const cached = this.cache.get(key);
|
|
361
|
-
|
|
362
|
-
if (cached && Date.now() - cached.timestamp < this.ttl) {
|
|
363
|
-
return cached.data;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
const data = await this.discovery.getAPIResources();
|
|
367
|
-
this.cache.set(key, { data, timestamp: Date.now() });
|
|
368
|
-
return data;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
```
|
|
372
|
-
|
|
373
|
-
### 2. Graceful Degradation
|
|
374
|
-
|
|
375
|
-
Always handle partial failures gracefully:
|
|
376
|
-
|
|
377
|
-
```typescript
|
|
378
|
-
async function discoverWithFallback(): Promise<ResourceMap> {
|
|
379
|
-
try {
|
|
380
|
-
return await discovery.discoverResources();
|
|
381
|
-
} catch (error) {
|
|
382
|
-
console.warn('Full discovery failed, falling back to basic resources:', error.message);
|
|
383
|
-
|
|
384
|
-
try {
|
|
385
|
-
const resources = await discovery.getAPIResources();
|
|
386
|
-
return { resources, custom: [] };
|
|
387
|
-
} catch (fallbackError) {
|
|
388
|
-
console.error('Basic discovery also failed:', fallbackError.message);
|
|
389
|
-
throw fallbackError;
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
```
|
|
394
|
-
|
|
395
|
-
### 3. Progressive Enhancement
|
|
396
|
-
|
|
397
|
-
Use discovery data to progressively enhance functionality:
|
|
398
|
-
|
|
399
|
-
```typescript
|
|
400
|
-
async function buildResourceMenu(): Promise<MenuItems[]> {
|
|
401
|
-
const baseItems = [
|
|
402
|
-
{ name: 'Pods', kind: 'Pod' },
|
|
403
|
-
{ name: 'Services', kind: 'Service' },
|
|
404
|
-
{ name: 'Deployments', kind: 'Deployment' }
|
|
405
|
-
];
|
|
406
|
-
|
|
407
|
-
try {
|
|
408
|
-
const resources = await discovery.getAPIResources();
|
|
409
|
-
const crds = await discovery.discoverCRDs();
|
|
410
|
-
|
|
411
|
-
// Add available standard resources
|
|
412
|
-
const enhancedItems = resources
|
|
413
|
-
.filter(r => !baseItems.some(b => b.kind === r.kind))
|
|
414
|
-
.map(r => ({ name: r.kind, kind: r.kind, group: r.group }));
|
|
415
|
-
|
|
416
|
-
// Add custom resources
|
|
417
|
-
const customItems = crds.map(crd => ({
|
|
418
|
-
name: crd.kind,
|
|
419
|
-
kind: crd.kind,
|
|
420
|
-
group: crd.group,
|
|
421
|
-
custom: true
|
|
422
|
-
}));
|
|
423
|
-
|
|
424
|
-
return [...baseItems, ...enhancedItems, ...customItems];
|
|
425
|
-
} catch (error) {
|
|
426
|
-
console.warn('Enhanced menu failed, using basic items:', error.message);
|
|
427
|
-
return baseItems;
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
```
|
|
431
|
-
|
|
432
|
-
## Configuration
|
|
433
|
-
|
|
434
|
-
### Kubeconfig Resolution
|
|
435
|
-
|
|
436
|
-
The discovery engine automatically resolves kubeconfig paths in priority order:
|
|
437
|
-
|
|
438
|
-
1. **Custom path** provided in constructor
|
|
439
|
-
2. **KUBECONFIG environment variable** (first path if multiple)
|
|
440
|
-
3. **Default path** (`~/.kube/config`)
|
|
441
|
-
|
|
442
|
-
```typescript
|
|
443
|
-
// Explicit path
|
|
444
|
-
const discovery1 = new KubernetesDiscovery({
|
|
445
|
-
kubeconfigPath: './custom-kubeconfig.yaml'
|
|
446
|
-
});
|
|
447
|
-
|
|
448
|
-
// Environment variable (KUBECONFIG=/path/to/config)
|
|
449
|
-
const discovery2 = new KubernetesDiscovery();
|
|
450
|
-
|
|
451
|
-
// Default path (~/.kube/config)
|
|
452
|
-
const discovery3 = new KubernetesDiscovery();
|
|
453
|
-
```
|
|
454
|
-
|
|
455
|
-
### Runtime Configuration
|
|
456
|
-
|
|
457
|
-
```typescript
|
|
458
|
-
// Change kubeconfig at runtime
|
|
459
|
-
discovery.setKubeconfigPath('./new-config.yaml');
|
|
460
|
-
await discovery.connect(); // Reconnect with new config
|
|
461
|
-
|
|
462
|
-
// Check current configuration
|
|
463
|
-
console.log('Using kubeconfig:', discovery.getKubeconfigPath());
|
|
464
|
-
console.log('Connected:', discovery.isConnected());
|
|
465
|
-
```
|
|
466
|
-
|
|
467
|
-
## Testing and Validation
|
|
468
|
-
|
|
469
|
-
### Manual Validation
|
|
470
|
-
|
|
471
|
-
Always validate discovery results manually:
|
|
472
|
-
|
|
473
|
-
```typescript
|
|
474
|
-
// CLI validation
|
|
475
|
-
dot-ai discover --kubeconfig ./kubeconfig.yaml --output table
|
|
476
|
-
dot-ai discover --kubeconfig ./kubeconfig.yaml --output json
|
|
477
|
-
|
|
478
|
-
// Programmatic validation
|
|
479
|
-
const resources = await discovery.getAPIResources();
|
|
480
|
-
console.log(`Discovered ${resources.length} resources`);
|
|
481
|
-
console.log('Sample resources:', resources.slice(0, 3).map(r => r.kind));
|
|
482
|
-
|
|
483
|
-
const explanation = await discovery.explainResource('Pod');
|
|
484
|
-
console.log(`Pod schema has ${explanation.fields.length} fields`);
|
|
485
|
-
```
|
|
486
|
-
|
|
487
|
-
### Test Coverage
|
|
488
|
-
|
|
489
|
-
The discovery engine maintains comprehensive test coverage:
|
|
490
|
-
- **Unit tests**: All core methods and error conditions
|
|
491
|
-
- **Integration tests**: Real cluster connectivity and discovery
|
|
492
|
-
- **TDD tests**: Error handling and graceful degradation
|
|
493
|
-
- **Manual validation**: CLI output and data structure verification
|
|
494
|
-
|
|
495
|
-
## Migration and Compatibility
|
|
496
|
-
|
|
497
|
-
### Version Compatibility
|
|
498
|
-
|
|
499
|
-
The discovery engine is designed to work across Kubernetes versions:
|
|
500
|
-
- Uses `kubectl` for maximum compatibility
|
|
501
|
-
- Gracefully handles missing APIs in older clusters
|
|
502
|
-
- Provides version-specific capability detection
|
|
503
|
-
|
|
504
|
-
### Data Structure Evolution
|
|
505
|
-
|
|
506
|
-
When extending data structures, maintain backward compatibility:
|
|
507
|
-
- Add optional fields with sensible defaults
|
|
508
|
-
- Preserve existing field names and types
|
|
509
|
-
- Document breaking changes clearly
|
|
510
|
-
|
|
511
|
-
## Conclusion
|
|
512
|
-
|
|
513
|
-
The Kubernetes Discovery Engine provides a solid foundation for building intelligent Kubernetes tooling. By exposing comprehensive, unfiltered discovery data through well-defined interfaces, it enables higher-level components to make informed decisions about cluster capabilities and resource selection.
|
|
514
|
-
|
|
515
|
-
The key to successful integration is understanding that the discovery engine provides raw capabilities - it's up to consuming components to interpret this data appropriately for their specific use cases.
|