-
Notifications
You must be signed in to change notification settings - Fork 1
initial setup for bind gvk to k8s client #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds GVK (Group/Version/Kind) to Kubernetes client binding functionality by introducing a registry system that maps Kubernetes resources to their generated client methods and types.
- Adds
opsIndex
configuration option to enable GVK-based operations registry - Implements qualified type naming strategy to handle resource name conflicts
- Generates ResourceTypeMap and utility types for type-safe GVK operations
Reviewed Changes
Copilot reviewed 3 out of 11 changed files in this pull request and generated 7 comments.
File | Description |
---|---|
packages/schema-sdk/src/types.ts | Adds opsIndex configuration options for GVK registry generation |
packages/schema-sdk/src/openapi.ts | Implements GVK-based type naming, interface renaming, and registry generation logic |
packages/schema-sdk/tests/openapi.extended.generate.test.ts | Adds test cases for GVK functionality and qualified naming strategy |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
options: OpenAPIOptions | ||
): string => { | ||
const { group, version, kind } = gvk; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Extra blank line should be removed for consistent formatting.
Copilot uses AI. Check for mistakes.
options: OpenAPIOptions | ||
): string => { | ||
const { group, version, kind } = gvk; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Extra blank line should be removed for consistent formatting.
Copilot uses AI. Check for mistakes.
const groupParts = group.split('.').map(part => toPascalCase(part)).join(''); | ||
const versionPart = toPascalCase(version); | ||
const qualifiedName = `${groupParts}${versionPart}${toPascalCase(kind)}`; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Extra blank line should be removed for consistent formatting.
Copilot uses AI. Check for mistakes.
packages/schema-sdk/src/openapi.ts
Outdated
// @ts-ignore | ||
const operation: Operation = (pathItem as any)[m]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use proper type assertion instead of @ts-ignore. Consider using (pathItem as any)[m] as Operation | undefined
and handle the undefined case explicitly.
// @ts-ignore | |
const operation: Operation = (pathItem as any)[m]; | |
const operation = (pathItem as any)[m] as Operation | undefined; |
Copilot uses AI. Check for mistakes.
packages/schema-sdk/src/openapi.ts
Outdated
// @ts-ignore | ||
const operation: Operation = (pathItem as any)[m]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use proper type assertion instead of @ts-ignore. Consider using (pathItem as any)[m] as Operation | undefined
and handle the undefined case explicitly.
// @ts-ignore | |
const operation: Operation = (pathItem as any)[m]; | |
// Use proper type assertion instead of @ts-ignore | |
const operation = (pathItem as any)[m] as Operation | undefined; |
Copilot uses AI. Check for mistakes.
packages/schema-sdk/src/openapi.ts
Outdated
// @ts-ignore | ||
const operation: Operation = (pathItem as any)[m]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use proper type assertion instead of @ts-ignore. Consider using (pathItem as any)[m] as Operation | undefined
and handle the undefined case explicitly.
// @ts-ignore | |
const operation: Operation = (pathItem as any)[m]; | |
const operation = (pathItem as any)[m] as Operation | undefined; |
Copilot uses AI. Check for mistakes.
packages/schema-sdk/src/openapi.ts
Outdated
// @ts-ignore | ||
const operation: Operation = (pathItem as any)[m]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use proper type assertion instead of @ts-ignore. Consider using (pathItem as any)[m] as Operation | undefined
and handle the undefined case explicitly.
// @ts-ignore | |
const operation: Operation = (pathItem as any)[m]; | |
const operation = (pathItem as any)[m] as Operation | undefined; |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
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 4 out of 12 changed files in this pull request and generated 5 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
) => { | ||
// @ts-ignore | ||
const operation: Operation = pathItem[method]; | ||
const operation: Operation | undefined = pathItem[method]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type assertion is incorrect. pathItem[method]
should be cast as pathItem[method as keyof OpenAPIPathItem] as Operation | undefined
to properly access the method property on the pathItem object.
const operation: Operation | undefined = pathItem[method]; | |
const operation: Operation | undefined = pathItem[method as keyof OpenAPIPathItem] as Operation | undefined; |
Copilot uses AI. Check for mistakes.
// @ts-ignore | ||
const operation: Operation = pathItem[method]; | ||
if (!shouldIncludeOperation(options, pathItem, path, method as any)) | ||
const operation: Operation | undefined = pathItem[method as keyof OpenAPIPathItem] as Operation | undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] This type assertion pattern is repeated multiple times throughout the file. Consider extracting this into a helper function like getOperationFromPathItem(pathItem: OpenAPIPathItem, method: string): Operation | undefined
to reduce duplication and improve maintainability.
Copilot uses AI. Check for mistakes.
const { group, version, kind } = gvk; | ||
|
||
// Handle core group (empty group) and normalize group names | ||
const groupName = group === '' ? 'Core' : toPascalCase(group.replace(/\./g, '')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The magic string 'Core' is hardcoded here but should use the configurable emptyGroupLabel
from options. This creates inconsistency with the configurable label used elsewhere in the code.
const groupName = group === '' ? 'Core' : toPascalCase(group.replace(/\./g, '')); | |
const groupName = group === '' ? (options.emptyGroupLabel || 'Core') : toPascalCase(group.replace(/\./g, '')); |
Copilot uses AI. Check for mistakes.
gvk: { group: string; version: string; kind: string }; | ||
scope: 'Namespaced' | 'Cluster' | 'Unknown'; | ||
types: { main: string; list?: string }; | ||
ops: any; // OperationSpec-ish |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using any
type defeats the purpose of TypeScript's type safety. Define a proper interface for the operations specification or use a more specific type like Record<string, unknown>
if the structure is truly variable.
ops: any; // OperationSpec-ish | |
ops: Record<string, unknown>; // OperationSpec-ish |
Copilot uses AI. Check for mistakes.
packages/schema-sdk/src/openapi.ts
Outdated
code = code.replace( | ||
/export type KubernetesResource = ([^;]+);/, | ||
(full, types) => { | ||
const parts = types | ||
.split('|') | ||
.map((part: string) => part.trim()) | ||
.filter(Boolean); | ||
if (parts.length <= 1) { | ||
return full; | ||
} | ||
const union = parts.map((part: string) => ` | ${part}`).join('\n'); | ||
return `export type KubernetesResource =\n${union};`; | ||
} | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Using regex string replacement on generated code is fragile and error-prone. Consider generating the union type directly in the AST generation phase instead of post-processing the string output.
code = code.replace( | |
/export type KubernetesResource = ([^;]+);/, | |
(full, types) => { | |
const parts = types | |
.split('|') | |
.map((part: string) => part.trim()) | |
.filter(Boolean); | |
if (parts.length <= 1) { | |
return full; | |
} | |
const union = parts.map((part: string) => ` | ${part}`).join('\n'); | |
return `export type KubernetesResource =\n${union};`; | |
} | |
); | |
// The KubernetesResource union type should be generated in multi-line format directly in the AST phase. |
Copilot uses AI. Check for mistakes.
Get a registry of sorts setup for the clients and operations
Closes: #11
Closes: #9