Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
feat: show a warning when an organization has no provisioners
  • Loading branch information
aslilac committed Aug 2, 2024
commit b9e5c6818b1e9eab58e8ce9a0e81c0e65441059e
7 changes: 7 additions & 0 deletions docs/admin/provisioners.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ There are two exceptions:
**Organization-scoped Provisioners** can pick up build jobs created by any user.
These provisioners always have the implicit tags `scope=organization owner=""`.

```shell
coder provisionerd start --org <organization_name>
```

If you omit the `--org` argument, the provisioner will be assigned to the
default organization.

```shell
coder provisionerd start
```
Expand Down
12 changes: 12 additions & 0 deletions site/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,18 @@ class ApiMethods {
return response.data;
};

/**
* @param organization Can be the organization's ID or name
*/
getProvisionerDaemonsByOrganization = async (
organization: string,
): Promise<TypesGen.ProvisionerDaemon[]> => {
const response = await this.axios.get<TypesGen.ProvisionerDaemon[]>(
`/api/v2/organizations/${organization}/provisionerdaemons`,
);
return response.data;
};

getTemplate = async (templateId: string): Promise<TypesGen.Template> => {
const response = await this.axios.get<TypesGen.Template>(
`/api/v2/templates/${templateId}`,
Expand Down
54 changes: 43 additions & 11 deletions site/src/pages/CreateTemplatePage/CreateTemplateForm.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import Alert from "@mui/material/Alert";

Check failure on line 1 in site/src/pages/CreateTemplatePage/CreateTemplateForm.tsx

View workflow job for this annotation

GitHub Actions / lint

'@mui/material/Alert' import is restricted from being used. You should use the Alert component provided on components/Alert/Alert

Check failure on line 1 in site/src/pages/CreateTemplatePage/CreateTemplateForm.tsx

View workflow job for this annotation

GitHub Actions / lint

'@mui/material/Alert' import is restricted from being used. You should use the Alert component provided on components/Alert/Alert

Check failure on line 1 in site/src/pages/CreateTemplatePage/CreateTemplateForm.tsx

View workflow job for this annotation

GitHub Actions / fmt

'@mui/material/Alert' import is restricted from being used. You should use the Alert component provided on components/Alert/Alert
import Link from "@mui/material/Link";
import TextField from "@mui/material/TextField";
import { useFormik } from "formik";
import camelCase from "lodash/camelCase";
import capitalize from "lodash/capitalize";
import { useState, type FC } from "react";
import { useQuery } from "react-query";
import { useSearchParams } from "react-router-dom";
import * as Yup from "yup";
import { API } from "api/api";
import type {
Organization,
ProvisionerJobLog,
Expand All @@ -23,6 +27,7 @@
import { IconField } from "components/IconField/IconField";
import { OrganizationAutocomplete } from "components/OrganizationAutocomplete/OrganizationAutocomplete";
import { SelectedTemplate } from "pages/CreateWorkspacePage/SelectedTemplate";
import { docs } from "utils/docs";
import {
nameValidator,
getFormHelpers,
Expand Down Expand Up @@ -210,6 +215,18 @@
});
const getFieldHelpers = getFormHelpers<CreateTemplateFormData>(form, error);

const warnAboutProvisionersQuery = useQuery({
enabled: showOrganizationPicker && Boolean(selectedOrg),
queryKey: ["warnAboutProvisioners", selectedOrg?.id],
queryFn: async () => {
const provisioners = await API.getProvisionerDaemonsByOrganization(
selectedOrg!.id,
);

return provisioners.length === 0;
},
});

return (
<HorizontalForm onSubmit={form.handleSubmit}>
{/* General info */}
Expand All @@ -232,17 +249,20 @@
)}

{showOrganizationPicker && (
<OrganizationAutocomplete
{...getFieldHelpers("organization_id")}
required
label="Belongs to"
value={selectedOrg}
onChange={(newValue) => {
setSelectedOrg(newValue);
void form.setFieldValue("organization", newValue?.id || "");
}}
size="medium"
/>
<>
{warnAboutProvisionersQuery.data && <ProvisionerWarning />}
<OrganizationAutocomplete
{...getFieldHelpers("organization_id")}
required
label="Belongs to"
value={selectedOrg}
onChange={(newValue) => {
setSelectedOrg(newValue);
void form.setFieldValue("organization", newValue?.id || "");
}}
size="medium"
/>
</>
)}

{"copiedTemplate" in props && (
Expand Down Expand Up @@ -369,3 +389,15 @@
form.setFieldValue("display_name", capitalize(name)),
]);
};

const ProvisionerWarning: FC = () => {
return (
<Alert severity="warning" css={{ marginBottom: 16 }}>
This organization does not have any provisioners. Before you create a
template, you'll need to configure a provisioner.{" "}

Check failure on line 397 in site/src/pages/CreateTemplatePage/CreateTemplateForm.tsx

View workflow job for this annotation

GitHub Actions / lint

`'` can be escaped with `&apos;`, `&lsquo;`, `&#39;`, `&rsquo;`

Check failure on line 397 in site/src/pages/CreateTemplatePage/CreateTemplateForm.tsx

View workflow job for this annotation

GitHub Actions / lint

`'` can be escaped with `&apos;`, `&lsquo;`, `&#39;`, `&rsquo;`

Check failure on line 397 in site/src/pages/CreateTemplatePage/CreateTemplateForm.tsx

View workflow job for this annotation

GitHub Actions / fmt

`'` can be escaped with `&apos;`, `&lsquo;`, `&#39;`, `&rsquo;`
<Link href={docs("/admin/provisioners#organization-scoped-provisioners")}>
See our documentation.
</Link>
</Alert>
);
};
Loading