Skip to content

Commit

Permalink
feat: autoDetach for workshopProvisions (#1951)
Browse files Browse the repository at this point in the history
* feat: autoDetach for workshopProvisions
  • Loading branch information
aleixhub authored Jun 10, 2024
1 parent 3e17643 commit f2a86e7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
19 changes: 12 additions & 7 deletions catalog/ui/src/app/Catalog/CatalogItemForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ const CatalogItemFormData: React.FC<{ catalogItemName: string; catalogNamespaceN
parameters: parameterValues,
startDelay: provisionStartDelay,
workshop: workshop,
useAutoDetach: formState.useAutoDetach,
});
if (scheduled !== null) {
try {
Expand Down Expand Up @@ -850,6 +851,10 @@ const CatalogItemFormData: React.FC<{ catalogItemName: string; catalogNamespaceN
/>
</div>
</FormGroup>
</>
) : null}
<>
{isAdmin ? (
<FormGroup key="auto-detach-switch" fieldId="auto-detach-switch">
<div className="catalog-item-form__group-control--single">
<Switch
Expand All @@ -858,17 +863,17 @@ const CatalogItemFormData: React.FC<{ catalogItemName: string; catalogNamespaceN
label="Keep instance if provision fails (only visible to admins)"
isChecked={!formState.useAutoDetach}
hasCheckIcon
onChange={(isChecked) =>
onChange={(isChecked) => {
dispatchFormState({
type: 'useAutoDetach',
useAutoDetach: !isChecked,
})
}
});
}}
/>
</div>
</FormGroup>
</>
) : null}
) : null}
</>

{catalogItem.spec.termsOfService ? (
<TermsOfService
Expand Down Expand Up @@ -911,9 +916,9 @@ const CatalogItemFormData: React.FC<{ catalogItemName: string; catalogNamespaceN
Schedule{' '}
<span
style={{
backgroundColor: submitRequestEnabled ? '#f0f0f0' : '#bee1f4',
backgroundColor: !submitRequestEnabled ? '#f0f0f0' : '#bee1f4',
borderRadius: '10px',
color: submitRequestEnabled ? '#8a8d90' : '#06c',
color: !submitRequestEnabled ? '#8a8d90' : '#06c',
fontStyle: 'italic',
fontWeight: 300,
fontSize: '12px',
Expand Down
9 changes: 9 additions & 0 deletions catalog/ui/src/app/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type CreateWorkshopPovisionOpt = {
parameters: any;
startDelay: number;
workshop: Workshop;
useAutoDetach: boolean;
};

export type CreateServiceRequestParameterValues = {
Expand Down Expand Up @@ -699,6 +700,7 @@ export async function createWorkshopProvision({
parameters,
startDelay,
workshop,
useAutoDetach,
}: CreateWorkshopPovisionOpt) {
const definition: WorkshopProvision = {
apiVersion: `${BABYLON_DOMAIN}/v1`,
Expand Down Expand Up @@ -736,6 +738,13 @@ export async function createWorkshopProvision({
parameters: parameters,
startDelay: startDelay,
workshopName: workshop.metadata.name,
...(useAutoDetach
? {
autoDetach: {
when: `status.resources | json_query("[?state.spec.vars.current_state == 'provision-failed']") | length != 0`,
},
}
: {}),
},
};

Expand Down
3 changes: 3 additions & 0 deletions catalog/ui/src/app/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,9 @@ export interface WorkshopProvisionSpec {
start?: string;
end?: string;
};
autoDetach?: {
when: string;
};
}

export interface WorkshopSpec {
Expand Down

0 comments on commit f2a86e7

Please sign in to comment.