Skip to content
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

fix: always order by apiVersion, kind, metadata, spec #61

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/cli/src/generateCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,21 @@ function morph() {
],
};

const preferredOrder = ['apiVersion', 'kind', 'metadata', 'spec'];
const orderedProps = classDeclaration.getProperties().sort((a, b) => {
const aIndex = preferredOrder.indexOf(a.getName());
const bIndex = preferredOrder.indexOf(b.getName());
if (aIndex === -1 && bIndex === -1) return 0;
if (aIndex === -1) return 1;
if (bIndex === -1) return -1;
return aIndex - bIndex;
});

c.statements = new Array<StatementStructures>();
c.statements.push('super(args.metadata?.name || name);');
for (const prop of classDeclaration.getProperties()) {
for (const [i, prop] of orderedProps.entries()) {
prop.setIsReadonly(true);
classDeclaration.getProperty(prop.getName())?.setOrder(i);
const interfaceProp: PropertySignatureStructure = {
kind: StructureKind.PropertySignature,
name: prop.getName(),
Expand Down
22 changes: 11 additions & 11 deletions packages/core/src/models/CSIStorageCapacityv1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { K8sApp } from '../K8sApp.js';
import { NamespacedObjectMetav1, NamespacedApiObject } from '../ApiObject.js';

export interface CSIStorageCapacityv1Args {
readonly metadata?: NamespacedObjectMetav1;
readonly capacity?: number | string;
readonly maximumVolumeSize?: number | string;
readonly metadata?: NamespacedObjectMetav1;
readonly nodeTopology?: LabelSelectorv1;
readonly storageClassName: string;
}
Expand All @@ -18,22 +18,22 @@ export class CSIStorageCapacityv1 extends NamespacedApiObject {
* 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
*/
readonly apiVersion = 'storage.k8s.io/v1';
/**
* capacity is the value reported by the CSI driver in its GetCapacityResponse for a GetCapacityRequest with topology and parameters that match the previous fields. The semantic is currently (CSI spec 1.2) defined as: The available capacity, in bytes, of the storage that can be used to provision volumes. If not set, that information is currently unavailable.
*/
readonly capacity?: number | string;
/**
* 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
*/
readonly kind = 'CSIStorageCapacity';
/**
* maximumVolumeSize is the value reported by the CSI driver in its GetCapacityResponse for a GetCapacityRequest with topology and parameters that match the previous fields. This is defined since CSI spec 1.4.0 as the largest size that may be used in a CreateVolumeRequest.capacity_range.required_bytes field to create a volume with the same parameters as those in GetCapacityRequest. The corresponding value in the Kubernetes API is ResourceRequirements.Requests in a volume claim.
*/
readonly maximumVolumeSize?: number | string;
/**
* Standard object\'s metadata. The name has no particular meaning. It must be a DNS subdomain (dots allowed, 253 characters). To ensure that there are no conflicts with other CSI drivers on the cluster, the recommendation is to use csisc-<uuid>, a generated name, or a reverse-domain name which ends with the unique CSI driver name. Objects are namespaced. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
*/
readonly metadata: NamespacedObjectMetav1;
/**
* capacity is the value reported by the CSI driver in its GetCapacityResponse for a GetCapacityRequest with topology and parameters that match the previous fields. The semantic is currently (CSI spec 1.2) defined as: The available capacity, in bytes, of the storage that can be used to provision volumes. If not set, that information is currently unavailable.
*/
readonly capacity?: number | string;
/**
* maximumVolumeSize is the value reported by the CSI driver in its GetCapacityResponse for a GetCapacityRequest with topology and parameters that match the previous fields. This is defined since CSI spec 1.4.0 as the largest size that may be used in a CreateVolumeRequest.capacity_range.required_bytes field to create a volume with the same parameters as those in GetCapacityRequest. The corresponding value in the Kubernetes API is ResourceRequirements.Requests in a volume claim.
*/
readonly maximumVolumeSize?: number | string;
/**
* nodeTopology defines which nodes have access to the storage for which capacity was reported. If not set, the storage is not accessible from any node in the cluster. If empty, the storage is accessible from all nodes. This field is immutable.
*/
Expand All @@ -45,10 +45,10 @@ export class CSIStorageCapacityv1 extends NamespacedApiObject {

constructor(app: K8sApp, name: string, args: CSIStorageCapacityv1Args) {
super(args.metadata?.name || name);
this.capacity = args.capacity;
this.maximumVolumeSize = args.maximumVolumeSize;
this.metadata = args.metadata || { name };
this.metadata.name ??= name;
this.capacity = args.capacity;
this.maximumVolumeSize = args.maximumVolumeSize;
this.nodeTopology = args.nodeTopology;
this.storageClassName = args.storageClassName;
app.addResource(this);
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/models/ClusterRolev1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,15 @@ import { K8sApp } from '../K8sApp.js';
import { ApiObject } from '../ApiObject.js';

export interface ClusterRolev1Args {
readonly aggregationRule?: AggregationRulev1;
readonly metadata?: ObjectMetav1;
readonly aggregationRule?: AggregationRulev1;
readonly rules?: Array<PolicyRulev1>;
}

/**
* ClusterRole is a cluster level, logical grouping of PolicyRules that can be referenced as a unit by a RoleBinding or ClusterRoleBinding.
*/
export class ClusterRolev1 extends ApiObject {
/**
* AggregationRule is an optional field that describes how to build the Rules for this ClusterRole. If AggregationRule is set, then the Rules are controller managed and direct changes to Rules will be stomped by the controller.
*/
readonly aggregationRule?: AggregationRulev1;
/**
* 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
*/
Expand All @@ -30,16 +26,20 @@ export class ClusterRolev1 extends ApiObject {
* Standard object\'s metadata.
*/
readonly metadata: ObjectMetav1;
/**
* AggregationRule is an optional field that describes how to build the Rules for this ClusterRole. If AggregationRule is set, then the Rules are controller managed and direct changes to Rules will be stomped by the controller.
*/
readonly aggregationRule?: AggregationRulev1;
/**
* Rules holds all the PolicyRules for this ClusterRole
*/
readonly rules?: Array<PolicyRulev1>;

constructor(app: K8sApp, name: string, args: ClusterRolev1Args) {
super(args.metadata?.name || name);
this.aggregationRule = args.aggregationRule;
this.metadata = args.metadata || { name };
this.metadata.name ??= name;
this.aggregationRule = args.aggregationRule;
this.rules = args.rules;
app.addResource(this);
}
Expand Down
22 changes: 11 additions & 11 deletions packages/core/src/models/ConfigMapv1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { K8sApp } from '../K8sApp.js';
import { NamespacedObjectMetav1, NamespacedApiObject } from '../ApiObject.js';

export interface ConfigMapv1Args {
readonly metadata?: NamespacedObjectMetav1;
readonly binaryData?: { [key: string]: string };
readonly data?: { [key: string]: string };
readonly immutable?: boolean;
readonly metadata?: NamespacedObjectMetav1;
}

/**
Expand All @@ -16,6 +16,14 @@ export class ConfigMapv1 extends NamespacedApiObject {
* 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
*/
readonly apiVersion = '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
*/
readonly kind = 'ConfigMap';
/**
* Standard object\'s metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
*/
readonly metadata: NamespacedObjectMetav1;
/**
* BinaryData contains the binary data. Each key must consist of alphanumeric characters, \'-\', \'_\' or \'.\'. BinaryData can contain byte sequences that are not in the UTF-8 range. The keys stored in BinaryData must not overlap with the ones in the Data field, this is enforced during validation process. Using this field will require 1.10+ apiserver and kubelet.
*/
Expand All @@ -28,22 +36,14 @@ export class ConfigMapv1 extends NamespacedApiObject {
* Immutable, if set to true, ensures that data stored in the ConfigMap cannot be updated (only object metadata can be modified). If not set to true, the field can be modified at any time. Defaulted to nil.
*/
readonly immutable?: boolean;
/**
* 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
*/
readonly kind = 'ConfigMap';
/**
* Standard object\'s metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
*/
readonly metadata: NamespacedObjectMetav1;

constructor(app: K8sApp, name: string, args: ConfigMapv1Args) {
super(args.metadata?.name || name);
this.metadata = args.metadata || { name };
this.metadata.name ??= name;
this.binaryData = args.binaryData;
this.data = args.data;
this.immutable = args.immutable;
this.metadata = args.metadata || { name };
this.metadata.name ??= name;
app.addResource(this);
}
}
12 changes: 6 additions & 6 deletions packages/core/src/models/ControllerRevisionv1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { K8sApp } from '../K8sApp.js';
import { NamespacedObjectMetav1, NamespacedApiObject } from '../ApiObject.js';

export interface ControllerRevisionv1Args {
readonly data?: any;
readonly metadata?: NamespacedObjectMetav1;
readonly data?: any;
readonly revision: number;
}

Expand All @@ -15,10 +15,6 @@ export class ControllerRevisionv1 extends NamespacedApiObject {
* 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
*/
readonly apiVersion = 'apps/v1';
/**
* Data is the serialized representation of the state.
*/
readonly data?: any;
/**
* 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
*/
Expand All @@ -27,16 +23,20 @@ export class ControllerRevisionv1 extends NamespacedApiObject {
* Standard object\'s metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
*/
readonly metadata: NamespacedObjectMetav1;
/**
* Data is the serialized representation of the state.
*/
readonly data?: any;
/**
* Revision indicates the revision of the state represented by Data.
*/
readonly revision: number;

constructor(app: K8sApp, name: string, args: ControllerRevisionv1Args) {
super(args.metadata?.name || name);
this.data = args.data;
this.metadata = args.metadata || { name };
this.metadata.name ??= name;
this.data = args.data;
this.revision = args.revision;
app.addResource(this);
}
Expand Down
30 changes: 15 additions & 15 deletions packages/core/src/models/CoreEventv1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { K8sApp } from '../K8sApp.js';
import { NamespacedObjectMetav1, NamespacedApiObject } from '../ApiObject.js';

export interface CoreEventv1Args {
readonly metadata?: NamespacedObjectMetav1;
readonly action?: string;
readonly count?: number;
readonly eventTime?: Date;
readonly firstTimestamp?: Date;
readonly involvedObject: ObjectReferencev1;
readonly lastTimestamp?: Date;
readonly message?: string;
readonly metadata?: NamespacedObjectMetav1;
readonly reason?: string;
readonly related?: ObjectReferencev1;
readonly reportingComponent?: string;
Expand All @@ -26,14 +26,22 @@ export interface CoreEventv1Args {
* Event is a report of an event somewhere in the cluster. Events have a limited retention time and triggers and messages may evolve with time. Event consumers should not rely on the timing of an event with a given Reason reflecting a consistent underlying trigger, or the continued existence of events with that Reason. Events should be treated as informative, best-effort, supplemental data.
*/
export class CoreEventv1 extends NamespacedApiObject {
/**
* What action was taken/failed regarding to the Regarding object.
*/
readonly action?: string;
/**
* 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
*/
readonly apiVersion = '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
*/
readonly kind = 'Event';
/**
* Standard object\'s metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
*/
readonly metadata: NamespacedObjectMetav1;
/**
* What action was taken/failed regarding to the Regarding object.
*/
readonly action?: string;
/**
* The number of times this event has occurred.
*/
Expand All @@ -50,10 +58,6 @@ export class CoreEventv1 extends NamespacedApiObject {
* The object that this event is about.
*/
readonly involvedObject: ObjectReferencev1;
/**
* 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
*/
readonly kind = 'Event';
/**
* The time at which the most recent occurrence of this event was recorded.
*/
Expand All @@ -62,10 +66,6 @@ export class CoreEventv1 extends NamespacedApiObject {
* A human-readable description of the status of this operation.
*/
readonly message?: string;
/**
* Standard object\'s metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
*/
readonly metadata: NamespacedObjectMetav1;
/**
* This should be a short, machine understandable string that gives the reason for the transition into the object\'s current status.
*/
Expand Down Expand Up @@ -97,15 +97,15 @@ export class CoreEventv1 extends NamespacedApiObject {

constructor(app: K8sApp, name: string, args: CoreEventv1Args) {
super(args.metadata?.name || name);
this.metadata = args.metadata || { name };
this.metadata.name ??= name;
this.action = args.action;
this.count = args.count;
this.eventTime = args.eventTime;
this.firstTimestamp = args.firstTimestamp;
this.involvedObject = args.involvedObject;
this.lastTimestamp = args.lastTimestamp;
this.message = args.message;
this.metadata = args.metadata || { name };
this.metadata.name ??= name;
this.reason = args.reason;
this.related = args.related;
this.reportingComponent = args.reportingComponent;
Expand Down
Loading