busola icon indicating copy to clipboard operation
busola copied to clipboard

Typescript types for Kubernetes resources

Open Lyczeq opened this issue 2 years ago • 7 comments

Description

Since we've decided to start using typescript in busola, it would be great to have types for the Kubernetes resources. There is a repository that allows generating those types by using Kubernetes' Open API but there's one problem that some properties are optional but should be required. Unfortunately the Open API lies us a bit because Kubernetes doesn't specify there which properties should be optional/required.

For example, the typescript's interface for Deployment, generated by the above repository says that all properties are optional. Even kind, apiVersion and spec, which isn't true.

export interface Deployment {
    /**
     * APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
     */
    apiVersion?: "apps/v1";
    /**
     * Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
     */
    kind?: "Deployment";
    /**
     * Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
     */
    metadata?: ObjectMeta;
    /**
     * Specification of the desired behavior of the Deployment.
     */
    spec?: DeploymentSpec;
    /**
     * Most recently observed status of the Deployment.
     */
    status?: DeploymentStatus;
}

It's great that the script generates those interfaces, but if we want to use it, we would have to modify it a little bit and change the optional types to required. The idea is to create a type that contains common k8s properties and extend above interfaces by this type.

Reasons

It would be great, to have types for the native/core Kubernetes' resources. It would be easier to maintain and develop our views.

Attachments

Lyczeq avatar Nov 08 '22 08:11 Lyczeq