Repository navigation
Description
Describe the bug
When reading a Kubernetes object, the request must include the apiVersion, kind, and metadata fields for the object. If the object is found, the response will include the spec and status.
It appears the KubernetesObjectApi.read() type definition was accidentally changed in the 1.0.0 release, so the request and response object are the same.
Old type definition in 0.x:
Lines 19 to 27 in 8d4a84c
| type KubernetesObjectHeader<T extends KubernetesObject | KubernetesObject> = Pick< | |
| T, | |
| 'apiVersion' | 'kind' | |
| > & { | |
| metadata: { | |
| name: string; | |
| namespace?: string; | |
| }; | |
| }; |
Lines 344 to 350 in 8d4a84c
| public async read<T extends KubernetesObject | KubernetesObject>( | |
| spec: KubernetesObjectHeader<T>, | |
| pretty?: string, | |
| exact?: boolean, | |
| exportt?: boolean, | |
| options: { headers: { [name: string]: string } } = { headers: {} }, | |
| ): Promise<{ body: T; response: http.IncomingMessage }> { |
The request payload is KubernetesObjectHeader<T> and the response is T.
New type definition in 1.0.0:
Lines 280 to 286 in 27ba0e1
| public async read<T extends KubernetesObject | KubernetesObject>( | |
| spec: T, | |
| pretty?: string, | |
| exact?: boolean, | |
| exportt?: boolean, | |
| options?: Configuration, | |
| ): Promise<T> { |
The request payload is T and the response is T.
Client Version
N/A
Server Version
N/A
To Reproduce
Results in an error:
Argument of type '{ apiVersion: "networking.gke.io/v1"; kind: "ManagedCertificate"; metadata: { name: string; namespace: string; }; }' is not assignable to parameter of type 'GKEManagedCertificate'.
Property 'spec' is missing in type '{ apiVersion: "networking.gke.io/v1"; kind: "ManagedCertificate"; metadata: { name: string; namespace: string; }; }' but required in type 'GKEManagedCertificate'.(2345)
input.tsx(10, 5): 'spec' is declared here.
Expected behavior
For any type, only the apiVersion, kind, and metadata fields should be required.
Example Code
import * as k8s from '@kubernetes/client-node';
interface GKEManagedCertificate extends k8s.KubernetesObject {
apiVersion: 'networking.gke.io/v1';
kind: 'ManagedCertificate';
metadata: {
name: string;
namespace?: string;
};
spec: {
domains: string[];
};
status?: {
certificateName: string;
certificateStatus: string;
domainStatus: { domain: string; status: string }[];
expireTime: string;
};
}
const client = new k8s.KubeConfig().makeApiClient(k8s.KubernetesObjectApi);
function readCertificate(name: string, namespace: string) {
const cert = client.read<GKEManagedCertificate>({
apiVersion: 'networking.gke.io/v1',
kind: 'ManagedCertificate',
metadata: { name, namespace }
});
return cert;
}Environment (please complete the following information):
- OS: macOS
- NodeJS Version: 20.17.0
- Cloud runtime: N/A
Additional context
This only affects type checking, not runtime.

Activity
brendandburns commentedon Dec 28, 2024
Looks like we need to cherry-pick this PR into the
mainbranchhttps://github.com/kubernetes-client/javascript/pull/854/files
I'd prefer to do that if it's possible since I think there are additional clean-ups/fixes in that PR.
jportner commentedon Dec 28, 2024
Thank you! I didn't see that PR before.
It appears all of the other changes from that PR (including tests) are already incorporated into the
mainbranch, see #2129 (comment)I also took a look just to make sure, and I came to the same conclusion. So I think my linked PR is probably all that needs to be changed to get
mainto parity unless you saw something else that I missed.