Skip to content

Commit

Permalink
fix(generation): Handle several untyped objects
Browse files Browse the repository at this point in the history
Some objects were not being caught as 'open'/untyped, so the conversion
layer was dropping their contents. Now they are passed thru as-is.
  • Loading branch information
danopia committed Aug 12, 2023
1 parent 2afc73a commit 96155d6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 40 deletions.
14 changes: 7 additions & 7 deletions generation/describe-shapes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ export class ShapeLibrary {
inner: this.readSchema(schema.additionalProperties, null),
};

} else if (schema['x-kubernetes-preserve-unknown-fields'] || localName == 'FieldsV1') {
return {
type: 'any',
reference: 'unknown',
description: schema.description ?? undefined,
};

} else if (schema.type === 'object') {
return {
type: 'structure',
Expand Down Expand Up @@ -127,13 +134,6 @@ export class ShapeLibrary {
description: schema.description ?? undefined,
};

} else if (schema['x-kubernetes-preserve-unknown-fields']) {
return {
type: 'any',
reference: 'unknown',
description: schema.description ?? undefined,
};

} else if (localName === 'JSONSchemaPropsOrBool') {
return {
type: 'any',
Expand Down
9 changes: 2 additions & 7 deletions lib/argo-cd/argoproj.io@v1alpha1/structs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ export interface ApplicationSource {
skipCrds?: boolean | null;
valueFiles?: Array<string> | null;
values?: string | null;
valuesObject?: {
} | null;
valuesObject?: c.JSONValue | null;
version?: string | null;
} | null;
kustomize?: {
Expand Down Expand Up @@ -118,7 +117,7 @@ export function toApplicationSource_helm(input: c.JSONValue) {
skipCrds: c.readOpt(obj["skipCrds"], c.checkBool),
valueFiles: c.readOpt(obj["valueFiles"], x => c.readList(x, c.checkStr)),
values: c.readOpt(obj["values"], c.checkStr),
valuesObject: c.readOpt(obj["valuesObject"], toApplicationSource_helm_valuesObject),
valuesObject: c.readOpt(obj["valuesObject"], c.identity),
version: c.readOpt(obj["version"], c.checkStr),
}}
export function toApplicationSource_kustomize(input: c.JSONValue) {
Expand Down Expand Up @@ -163,10 +162,6 @@ export function toApplicationSource_helm_parameters(input: c.JSONValue) {
name: c.readOpt(obj["name"], c.checkStr),
value: c.readOpt(obj["value"], c.checkStr),
}}
export function toApplicationSource_helm_valuesObject(input: c.JSONValue) {
const obj = c.checkObj(input);
return {
}}
export function toApplicationSource_kustomize_replicas(input: c.JSONValue) {
const obj = c.checkObj(input);
return {
Expand Down
14 changes: 2 additions & 12 deletions lib/builtin/meta@v1/structs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,7 @@ export function fromPreconditions(input: Preconditions): c.JSONValue {
Each key is either a '.' representing the field itself, and will always map to an empty set, or a string representing a sub-field or item. The string will follow one of these four formats: 'f:<name>', where <name> is the name of a field in a struct, or key in a map 'v:<value>', where <value> is the exact json formatted value of a list item 'i:<index>', where <index> is position of a item in a list 'k:<keys>', where <keys> is a map of a list item's key fields to their unique values If a key maps to an empty Fields value, the field that key represents is part of the set.
The exact format is defined in sigs.k8s.io/structured-merge-diff */
export interface FieldsV1 {
}
export function toFieldsV1(input: c.JSONValue): FieldsV1 {
const obj = c.checkObj(input);
return {
}}
export function fromFieldsV1(input: FieldsV1): c.JSONValue {
return {
...input,
}}
export type FieldsV1 = c.JSONValue;

/** A label selector is a label query over a set of resources. The result of matchLabels and matchExpressions are ANDed. An empty label selector matches all objects. A null label selector matches no objects. */
export interface LabelSelector {
Expand Down Expand Up @@ -305,7 +296,7 @@ export function toManagedFieldsEntry(input: c.JSONValue): ManagedFieldsEntry {
return {
apiVersion: c.readOpt(obj["apiVersion"], c.checkStr),
fieldsType: c.readOpt(obj["fieldsType"], c.checkStr),
fieldsV1: c.readOpt(obj["fieldsV1"], toFieldsV1),
fieldsV1: c.readOpt(obj["fieldsV1"], c.identity),
manager: c.readOpt(obj["manager"], c.checkStr),
operation: c.readOpt(obj["operation"], c.checkStr),
subresource: c.readOpt(obj["subresource"], c.checkStr),
Expand All @@ -314,7 +305,6 @@ export function toManagedFieldsEntry(input: c.JSONValue): ManagedFieldsEntry {
export function fromManagedFieldsEntry(input: ManagedFieldsEntry): c.JSONValue {
return {
...input,
fieldsV1: input.fieldsV1 != null ? fromFieldsV1(input.fieldsV1) : undefined,
time: input.time != null ? c.fromTime(input.time) : undefined,
}}

Expand Down
18 changes: 4 additions & 14 deletions lib/vpa/autoscaling.k8s.io@v1/structs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@ export interface VerticalPodAutoscalerCheckpoint {
} | null;
status?: {
cpuHistogram?: {
bucketWeights?: {
} | null;
bucketWeights?: c.JSONValue | null;
referenceTimestamp?: c.Time | null;
totalWeight?: number | null;
} | null;
firstSampleStart?: c.Time | null;
lastSampleStart?: c.Time | null;
lastUpdateTime?: c.Time | null;
memoryHistogram?: {
bucketWeights?: {
} | null;
bucketWeights?: c.JSONValue | null;
referenceTimestamp?: c.Time | null;
totalWeight?: number | null;
} | null;
Expand Down Expand Up @@ -84,25 +82,17 @@ export function toVerticalPodAutoscalerCheckpoint_status(input: c.JSONValue) {
export function toVerticalPodAutoscalerCheckpoint_status_cpuHistogram(input: c.JSONValue) {
const obj = c.checkObj(input);
return {
bucketWeights: c.readOpt(obj["bucketWeights"], toVerticalPodAutoscalerCheckpoint_status_cpuHistogram_bucketWeights),
bucketWeights: c.readOpt(obj["bucketWeights"], c.identity),
referenceTimestamp: c.readOpt(obj["referenceTimestamp"], c.toTime),
totalWeight: c.readOpt(obj["totalWeight"], c.checkNum),
}}
export function toVerticalPodAutoscalerCheckpoint_status_memoryHistogram(input: c.JSONValue) {
const obj = c.checkObj(input);
return {
bucketWeights: c.readOpt(obj["bucketWeights"], toVerticalPodAutoscalerCheckpoint_status_memoryHistogram_bucketWeights),
bucketWeights: c.readOpt(obj["bucketWeights"], c.identity),
referenceTimestamp: c.readOpt(obj["referenceTimestamp"], c.toTime),
totalWeight: c.readOpt(obj["totalWeight"], c.checkNum),
}}
export function toVerticalPodAutoscalerCheckpoint_status_cpuHistogram_bucketWeights(input: c.JSONValue) {
const obj = c.checkObj(input);
return {
}}
export function toVerticalPodAutoscalerCheckpoint_status_memoryHistogram_bucketWeights(input: c.JSONValue) {
const obj = c.checkObj(input);
return {
}}

export interface VerticalPodAutoscalerCheckpointList extends ListOf<VerticalPodAutoscalerCheckpoint> {
apiVersion?: "autoscaling.k8s.io/v1";
Expand Down

0 comments on commit 96155d6

Please sign in to comment.