Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat(project-creation): support Kubernetes cluster override for internal project creation (#49956)

Joaquim Moreno Prusib824acdfd204
diff --git a/apps/studio/components/interfaces/ProjectCreation/InternalOnlyConfiguration.tsx b/apps/studio/components/interfaces/ProjectCreation/InternalOnlyConfiguration.tsx
index 3779c2912f7..8bb3a6cde8a 100644
--- a/apps/studio/components/interfaces/ProjectCreation/InternalOnlyConfiguration.tsx
+++ b/apps/studio/components/interfaces/ProjectCreation/InternalOnlyConfiguration.tsx
@@ -2,7 +2,16 @@ import { useParams } from 'common'
import { useRef } from 'react'
import { UseFormReturn } from 'react-hook-form'
import { type CloudProvider } from 'shared-data'
-import { FormControl, FormField, Input, useWatch } from 'ui'
+import {
+ Checkbox,
+ FormControl,
+ FormDescription,
+ FormField,
+ FormItem,
+ FormLabel,
+ Input,
+ useWatch,
+} from 'ui'
import { CollapsibleCardSection } from 'ui-patterns/CollapsibleCardSection'
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
@@ -19,6 +28,9 @@ export const InternalOnlyConfiguration = ({ form }: InternalOnlyConfigurationPro
const { slug } = useParams()
const showNonProdFields = process.env.NEXT_PUBLIC_ENVIRONMENT !== 'prod'
const highAvailability = useWatch({ control: form.control, name: 'highAvailability' })
+ const cloudProvider = useWatch({ control: form.control, name: 'cloudProvider' })
+ const kubernetesClusterId = useWatch({ control: form.control, name: 'kubernetesClusterId' })
+ const isK8sProvider = cloudProvider === 'AWS_K8S' || cloudProvider === 'AWS_NIMBUS'
// Held here (outside the collapsible content) so the selector's last valid
// selection survives the section being collapsed and reopened.
const lastValidPostgresVersionSelection = useRef('')
@@ -89,6 +101,60 @@ export const InternalOnlyConfiguration = ({ form }: InternalOnlyConfigurationPro
</FormItemLayout>
)}
/>
+
+ {isK8sProvider && (
+ <FormField
+ control={form.control}
+ name="kubernetesClusterId"
+ render={({ field }) => (
+ <FormItemLayout
+ label="Kubernetes cluster ID"
+ layout="horizontal"
+ description="Override the Kubernetes cluster this project is created on, bypassing load-balancing. Use the full cluster ID (e.g. dev-gbl-a001-c003-k001-0-eksCluster-038b450), not the short cluster name (e.g. dev-gbl-a001-c003-k001)."
+ >
+ <FormControl>
+ {/* The backend matches against the kubernetes_clusters.id primary
+ key, which is the full `<cluster-name>-eksCluster-<hash>` value —
+ not the short cluster name shown elsewhere (e.g. admin_studio's
+ project page). The short name alone won't match any cluster. */}
+ <Input
+ placeholder="e.g dev-gbl-a001-c003-k001-0-eksCluster-038b450"
+ {...field}
+ autoComplete="off"
+ />
+ </FormControl>
+ </FormItemLayout>
+ )}
+ />
+ )}
+
+ {isK8sProvider && !!kubernetesClusterId && (
+ <FormField
+ control={form.control}
+ name="kubernetesClusterForce"
+ render={({ field }) => (
+ <FormItem className="flex items-start gap-3">
+ <FormControl>
+ <Checkbox
+ checked={field.value}
+ disabled={field.disabled}
+ onCheckedChange={(value) => field.onChange(value === true)}
+ />
+ </FormControl>
+ <div className="space-y-1">
+ <FormLabel className="text-sm text-foreground">
+ Force-deploy to this cluster
+ </FormLabel>
+ <FormDescription className="text-foreground-lighter">
+ Allows deliberately targeting a CORDONED cluster. PENDING and REMOVED
+ clusters remain ineligible, and the cluster still needs a mapped
+ filesystem to provision onto.
+ </FormDescription>
+ </div>
+ </FormItem>
+ )}
+ />
+ )}
</div>
</div>
)}
diff --git a/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.schema.ts b/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.schema.ts
index 38b3369873a..55f5ab2edbf 100644
--- a/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.schema.ts
+++ b/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.schema.ts
@@ -18,6 +18,12 @@ export const FormSchema = z
required_error: 'Please enter a Postgres version.',
}),
instanceType: z.string().optional(),
+ kubernetesClusterId: z
+ .string()
+ .trim()
+ .transform((value) => (value === '' ? undefined : value))
+ .optional(),
+ kubernetesClusterForce: z.boolean().optional(),
dbRegion: z.string({
required_error: 'Please select a region.',
}),
@@ -46,7 +52,15 @@ export const FormSchema = z
})
.superRefine(
(
- { dbPassStrength, dbPassStrengthWarning, highAvailability, cloudProvider, useOrioleDb },
+ {
+ dbPassStrength,
+ dbPassStrengthWarning,
+ highAvailability,
+ cloudProvider,
+ useOrioleDb,
+ kubernetesClusterId,
+ kubernetesClusterForce,
+ },
ctx
) => {
if (dbPassStrength < DEFAULT_MINIMUM_PASSWORD_STRENGTH) {
@@ -76,6 +90,23 @@ export const FormSchema = z
message: 'High availability is not supported with OrioleDB images',
})
}
+
+ if (kubernetesClusterId && cloudProvider !== 'AWS_K8S' && cloudProvider !== 'AWS_NIMBUS') {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ path: ['kubernetesClusterId'],
+ message:
+ 'Kubernetes cluster ID is only supported for Kubernetes-architecture cloud providers',
+ })
+ }
+
+ if (kubernetesClusterForce && !kubernetesClusterId) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ path: ['kubernetesClusterForce'],
+ message: 'Force-deploy has no effect without a Kubernetes cluster ID',
+ })
+ }
}
)
diff --git a/apps/studio/components/interfaces/ProjectCreation/ProjectCreationForm.tsx b/apps/studio/components/interfaces/ProjectCreation/ProjectCreationForm.tsx
index a3e0a1fc2f4..6d52c136078 100644
--- a/apps/studio/components/interfaces/ProjectCreation/ProjectCreationForm.tsx
+++ b/apps/studio/components/interfaces/ProjectCreation/ProjectCreationForm.tsx
@@ -162,6 +162,8 @@ export const ProjectCreationForm = ({
highAvailability: false,
postgresVersion: '',
instanceType: '',
+ kubernetesClusterId: '',
+ kubernetesClusterForce: false,
cloudProvider: PROVIDERS[defaultProvider].id,
dbPass: '',
dbPassStrength: 0,
@@ -188,6 +190,8 @@ export const ProjectCreationForm = ({
organization,
projectName: watchedProjectName,
highAvailability,
+ kubernetesClusterId: watchedKubernetesClusterId,
+ kubernetesClusterForce: watchedKubernetesClusterForce,
} = useWatch({ control: form.control })
const { dirtyFields } = useFormState(form)
const isDbRegionDirty = dirtyFields.dbRegion
@@ -405,6 +409,8 @@ export const ProjectCreationForm = ({
dbRegion,
postgresVersion,
instanceType,
+ kubernetesClusterId,
+ kubernetesClusterForce,
instanceSize,
dataApi,
dataApiDefaultPrivileges,
@@ -527,14 +533,19 @@ export const ProjectCreationForm = ({
: {}),
}
- if (customPostgresVersion || instanceType) {
+ if (customPostgresVersion || instanceType || kubernetesClusterId) {
data['customSupabaseRequest'] = {
- ami: {
- ...(customPostgresVersion && {
- search_tags: { 'tag:postgresVersion': customPostgresVersion },
- }),
- ...(instanceType && { instance_type: instanceType }),
- },
+ ...((customPostgresVersion || instanceType) && {
+ ami: {
+ ...(customPostgresVersion && {
+ search_tags: { 'tag:postgresVersion': customPostgresVersion },
+ }),
+ ...(instanceType && { instance_type: instanceType }),
+ },
+ }),
+ ...(kubernetesClusterId && { kubernetes_cluster_id: kubernetesClusterId }),
+ ...(kubernetesClusterId &&
+ kubernetesClusterForce && { kubernetes_cluster_force: kubernetesClusterForce }),
}
}
@@ -593,6 +604,16 @@ export const ProjectCreationForm = ({
}
}, [instanceSize, watchedInstanceSize, setValue])
+ useEffect(() => {
+ const isK8sProvider = cloudProvider === 'AWS_K8S' || cloudProvider === 'AWS_NIMBUS'
+ if (!isK8sProvider && watchedKubernetesClusterId) {
+ setValue('kubernetesClusterId', '', { shouldDirty: false, shouldValidate: false })
+ }
+ if ((!isK8sProvider || !watchedKubernetesClusterId) && watchedKubernetesClusterForce) {
+ setValue('kubernetesClusterForce', false, { shouldDirty: false, shouldValidate: false })
+ }
+ }, [cloudProvider, watchedKubernetesClusterId, watchedKubernetesClusterForce, setValue])
+
useEffect(() => {
if (!githubRepositoryName) return
if ((watchedProjectName ?? '').trim().length > 0) return