Files
Joaquim Moreno Prusi b824acdfd2 feat(project-creation): support Kubernetes cluster override for internal project creation (#49956)
## I have read the
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
file.

YES

## What kind of change does this PR introduce?

Feature, internal

## What is the current behavior?

When creating a project, the worker will use load balancing to decide
where to deploy a cluster.

## What is the new behavior?

An internal user can choose a specific cluster and even bypass the
CORDONED state by forcing deployment.


## Additional context

This PR adds kubernetesClusterId and kubernetesClusterForce to the
internal-only project creation form for K8S cloud providers, gated by
schema validation (provider-restricted; force requires an ID) and
cleared automatically on provider change. The override is a one-time
creation-time steer, not a persistent pin, and the UI copy reflects
that. Includes the matching
kubernetes_cluster_id/kubernetes_cluster_force request fields in the
generated platform API types.

<img width="1620" height="1352" alt="image"
src="https://github.com/user-attachments/assets/bd8965a1-cec8-4428-aac1-46d0bf3b89d3"
/>


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added Kubernetes cluster ID entry during project creation for
supported cloud providers.
  * Added an option to force deployment to a specified cluster.
* Clarified that eligible clusters must meet status and filesystem
requirements.

* **Bug Fixes**
* Prevented invalid or outdated Kubernetes settings from being submitted
when the provider or cluster selection changes.
  * Treated blank or whitespace-only cluster IDs as unset.
* Prevented force-deployment requests without a cluster ID or for
unsupported providers.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-09-15 13:46:49 +02:00

166 lines
6.8 KiB
TypeScript

import { useParams } from 'common'
import { useRef } from 'react'
import { UseFormReturn } from 'react-hook-form'
import { type CloudProvider } from 'shared-data'
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'
import { CloudProviderSelector } from './CloudProviderSelector'
import { PostgresVersionSelector } from './PostgresVersionSelector'
import { CreateProjectForm } from './ProjectCreation.schema'
import Panel from '@/components/ui/Panel'
interface InternalOnlyConfigurationProps {
form: UseFormReturn<CreateProjectForm>
}
export const InternalOnlyConfiguration = ({ form }: InternalOnlyConfigurationProps) => {
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('')
return (
<Panel.Content>
<CollapsibleCardSection
title="Internal-only Configuration"
description="These settings are only visible to internal staff"
>
<div className="flex flex-col gap-y-6">
<div className="flex flex-col gap-y-4">
<FormField
control={form.control}
name="postgresVersionSelection"
render={({ field }) => (
<PostgresVersionSelector
field={field}
form={form}
cloudProvider={form.getValues('cloudProvider') as CloudProvider}
organizationSlug={slug}
dbRegion={form.getValues('dbRegion')}
disabled={highAvailability}
lastValidSelectionRef={lastValidPostgresVersionSelection}
/>
)}
/>
</div>
{showNonProdFields && (
<div>
<p className="text-xs text-foreground-lighter mb-6">
The settings below are only applicable for local/staging projects
</p>
<div className="flex flex-col gap-y-4">
<CloudProviderSelector form={form} />
{!highAvailability && (
<FormField
control={form.control}
name="postgresVersion"
render={({ field }) => (
<FormItemLayout
label="Custom Postgres version"
layout="horizontal"
description="Specify a custom version of Postgres (defaults to the latest)."
>
<FormControl>
<Input placeholder="e.g 17.6.1.104" {...field} autoComplete="off" />
</FormControl>
</FormItemLayout>
)}
/>
)}
<FormField
control={form.control}
name="instanceType"
render={({ field }) => (
<FormItemLayout
label="Custom instance type"
layout="horizontal"
description="Specify a custom instance type."
>
<FormControl>
<Input placeholder="e.g t3.nano" {...field} autoComplete="off" />
</FormControl>
</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>
)}
</div>
</CollapsibleCardSection>
</Panel.Content>
)
}