-
Couldn't load subscription status.
- Fork 559
[WIP] Fix parsing of Knative Service YAML in version 1.4.0 #2671
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -165,13 +165,58 @@ export function normalizeResponseHeaders(response: Response): { [key: string]: s | |||||
| return normalizedHeaders; | ||||||
| } | ||||||
|
|
||||||
| export function getSerializationType(apiVersion?: string, kind?: string): string { | ||||||
| /** | ||||||
| * Built-in Kubernetes API groups that have generated TypeScript models. | ||||||
| * Custom resources and third-party API groups (like Knative) are not included. | ||||||
| */ | ||||||
| const BUILT_IN_API_GROUPS = new Set([ | ||||||
| 'core', // maps to "" (empty string) for core resources like Pod, Service, etc. | ||||||
| 'admissionregistration.k8s.io', | ||||||
| 'apiextensions.k8s.io', | ||||||
| 'apiregistration.k8s.io', | ||||||
| 'apps', | ||||||
| 'authentication.k8s.io', | ||||||
| 'authorization.k8s.io', | ||||||
| 'autoscaling', | ||||||
| 'batch', | ||||||
| 'certificates.k8s.io', | ||||||
| 'coordination.k8s.io', | ||||||
| 'discovery.k8s.io', | ||||||
| 'events.k8s.io', | ||||||
| 'flowcontrol.apiserver.k8s.io', | ||||||
| 'internal.apiserver.k8s.io', | ||||||
| 'networking.k8s.io', | ||||||
| 'node.k8s.io', | ||||||
| 'policy', | ||||||
| 'rbac.authorization.k8s.io', | ||||||
| 'resource.k8s.io', | ||||||
| 'scheduling.k8s.io', | ||||||
| 'storage.k8s.io', | ||||||
| 'storagemigration.k8s.io', | ||||||
| ]); | ||||||
|
|
||||||
| /** | ||||||
| * Check if the given API group is a built-in Kubernetes API group. | ||||||
| * @param group - The API group to check (e.g., "apps", "serving.knative.dev", "core") | ||||||
| * @returns true if the group is a built-in Kubernetes API group, false otherwise | ||||||
| */ | ||||||
| function isBuiltInApiGroup(group: string): boolean { | ||||||
| return BUILT_IN_API_GROUPS.has(group); | ||||||
| } | ||||||
|
|
||||||
| export function getSerializationType(apiVersion?: string, kind?: string): string | undefined { | ||||||
| if (apiVersion === undefined || kind === undefined) { | ||||||
| return 'KubernetesObject'; | ||||||
| } | ||||||
| // Types are defined in src/gen/api/models with the format "<Version><Kind>". | ||||||
| // Version and Kind are in PascalCase. | ||||||
| const gv = groupVersion(apiVersion); | ||||||
|
|
||||||
| // Only return a type name if this is a built-in Kubernetes API group | ||||||
| if (!isBuiltInApiGroup(gv.group)) { | ||||||
| return undefined; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Return 'KubernetesObject' here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Changed to return 'KubernetesObject' instead of undefined in commit 3bce4d5. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Changed to return 'KubernetesObject' instead of undefined in commit b0f3f4b. |
||||||
| } | ||||||
|
|
||||||
| const version = gv.version.charAt(0).toUpperCase() + gv.version.slice(1); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Perhaps add check so code doesn't throw when gv.version is undefined or malformed. (Keep getSerializationType protected for edge cases) |
||||||
| return `${version}${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.
Rather than requiring the caller to do this, just modify getSerializationType to return
KubernetesOjbectfor the non-native case.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.
Done. Modified getSerializationType to return 'KubernetesObject' for non-native cases and removed the ?? fallback operators from all callers in commit 3bce4d5.
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.
Done. Modified getSerializationType to return 'KubernetesObject' for non-native cases and removed the ?? fallback operators from all callers in commit b0f3f4b.