Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
garronej committed Dec 2, 2024
1 parent 957f261 commit f776dc3
Showing 1 changed file with 29 additions and 43 deletions.
72 changes: 29 additions & 43 deletions web/src/core/usecases/launcher/decoupledLogic/computeHelmValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,42 @@ export function computeHelmValues_rec(params: {
return constValue;
}

const helmValuesSchemaType = getJSONSchemaType(helmValuesSchema);

schema_is_object_with_known_properties: {
if (helmValuesSchemaType !== "object") {
break schema_is_object_with_known_properties;
}

const { properties } = helmValuesSchema;

if (properties === undefined) {
break schema_is_object_with_known_properties;
}

return Object.fromEntries(
Object.entries(properties).map(([propertyName, propertySchema]) => [
propertyName,
computeHelmValues_rec({
helmValuesSchema: propertySchema,
helmValuesYaml_parsed:
helmValuesYaml_parsed instanceof Object &&
!(helmValuesYaml_parsed instanceof Array)
? helmValuesYaml_parsed[propertyName]
: undefined,
xOnyxiaContext
})
])
);
}

use_x_onyxia_overwriteDefaultWith: {
const { overwriteDefaultWith } = helmValuesSchema["x-onyxia"] ?? {};

if (overwriteDefaultWith === undefined) {
break use_x_onyxia_overwriteDefaultWith;
}

if (
helmValuesSchema.type === "object" &&
helmValuesSchema.properties !== undefined
) {
break use_x_onyxia_overwriteDefaultWith;
}

const resolvedValue = resolveXOnyxiaValueReference({
expression: overwriteDefaultWith,
xOnyxiaContext
Expand Down Expand Up @@ -172,13 +194,6 @@ export function computeHelmValues_rec(params: {
break use_default;
}

if (
helmValuesSchema.type === "object" &&
helmValuesSchema.properties !== undefined
) {
break use_default;
}

const { isValid } = validateValueAgainstJSONSchema({
helmValuesSchema,
xOnyxiaContext,
Expand All @@ -192,35 +207,6 @@ export function computeHelmValues_rec(params: {
return defaultValue;
}

const helmValuesSchemaType = getJSONSchemaType(helmValuesSchema);

schema_is_object_with_known_properties: {
if (helmValuesSchemaType !== "object") {
break schema_is_object_with_known_properties;
}

const { properties } = helmValuesSchema;

if (properties === undefined) {
break schema_is_object_with_known_properties;
}

return Object.fromEntries(
Object.entries(properties).map(([propertyName, propertySchema]) => [
propertyName,
computeHelmValues_rec({
helmValuesSchema: propertySchema,
helmValuesYaml_parsed:
helmValuesYaml_parsed instanceof Object &&
!(helmValuesYaml_parsed instanceof Array)
? helmValuesYaml_parsed[propertyName]
: undefined,
xOnyxiaContext
})
])
);
}

use_values_yaml: {
if (helmValuesYaml_parsed === undefined) {
break use_values_yaml;
Expand Down

0 comments on commit f776dc3

Please sign in to comment.