From YAML to Forms: Inside Kuadrant's Policy Editor Architecture

Kuadrant Console Plugin: An OpenShift Dynamic Plugin
Kuadrant is an open-source project that manages API gateway policies on Kubernetes things like rate limiting, DNS configuration, TLS certificates and authentication.
Instead of writing kubectl commands or raw YAML files, engineers use the Kuadrant Console Plugin to create and manage these policies through a web interface.
But this isn't a standalone React app. It's an OpenShift Dynamic Plugin. A React application that runs inside the OpenShift Console.
It uses the openshift-console/dynamic-plugin-sdk to access Kubernetes APIs (k8sCreate, k8sUpdate, useK8sWatchResource), render YAML editors (ResourceYAMLEditor) and hook into the console's navigation and namespace context.
This means the plugin doesn't manage its own routing or authentication. OpenShift handles all of that.
The Problem
Currently, Kuadrant supports 7 policy types. But only 2 of them DNSPolicy and TLSPolicy have user-friendly form-based editors. The remaining 5 policies (RateLimitPolicy, TokenRateLimitPolicy, AuthPolicy, PlanPolicy and OIDCPolicy) force users to write raw YAML manually:
apiVersion: kuadrant.io/v1
kind: RateLimitPolicy
metadata:
name: example-ratelimitpolicy
spec:
targetRef:
group: gateway.networking.k8s.io
kind: Gateway
name: prod-web
limits:
toystore-api-per-username:
rates:
- limit: 100
window: "1s"
This is error-prone like a missing indent, a wrong field name or a typo in the targetRef can silently break the policy.
The goal is to bring all 5 remaining policies to the same level as DNSPolicy and TLSPolicy: guided forms with validation while keeping the option to switch to YAML for advanced users.
The Dual View Architecture: Form ↔ YAML
The core UX pattern in Kuadrant's policy editors is a dual view toggle.Currently, this dual view toggle is implemented only for DNSPolicy and TLSPolicy. The remaining 5 policies only show a raw YAML editor.
Here's how it works in KuadrantDNSPolicyCreatePage.tsx:
// KuadrantDNSPolicyCreatePage.tsx
const [createView, setCreateView] = React.useState<'form' | 'yaml'>('form');
// Radio toggle
<Radio label="Form View" isChecked={createView === 'form'} onChange={() => setCreateView('form')} />
<Radio label="YAML View" isChecked={createView === 'yaml'} onChange={() => setCreateView('yaml')} />
// Conditional rendering
{createView === 'form' ? (
<Form>{ /* form fields */ }</Form>
) : (
<ResourceYAMLEditor initialResource={yamlInput} create={create} onChange={handleYAMLChange} />
)}
When the user selects Form View, they see structured inputs like text fields, dropdowns, expandable sections. When they select YAML View, they see OpenShift's built-in ResourceYAMLEditor with the full policy YAML. The default view is always form so users start with the guided experience and can switch to YAML only when they need to.
The key insight here is that both views work on the same data. Whether you type a policy name in the form or edit it in the YAML, the result is identical. This is possible because of the bidirectional sync mechanism.
How Form State Becomes a Kubernetes Resource
This is the core of every policy form. Each form field is stored using React's useState and a builder function assembles them into a Kubernetes resource object.
In KuadrantDNSPolicyCreatePage.tsx, the form state looks like this:
const [policyName, setPolicyName] = React.useState('');
const [selectedGateway, setSelectedGateway] = React.useState({ name: '', namespace: '' });
// ... loadBalancing, healthCheck, providerRefs etc.
Every time the user types or selects something, the corresponding state updates. The createDNSPolicy() function then takes all these values and builds the Kubernetes resource:
const createDNSPolicy = () => ({
apiVersion: 'kuadrant.io/v1',
kind: 'DNSPolicy',
metadata: {
name: policyName, // ← from text input
namespace: selectedNamespace, // ← from OpenShift context
},
spec: {
targetRef: {
group: 'gateway.networking.k8s.io',
kind: 'Gateway',
name: selectedGateway.name, // ← from dropdown
},
loadBalancing: {
weight: loadBalancing.weight, // ← from number input
geo: loadBalancing.geo, // ← from text input
},
},
});
This is not just a form. It's a Kubernetes resource generator.
The form fields map directly to the YAML structure that Kubernetes expects. When the user clicks Save, this object is sent to the cluster via k8sCreate().
The same pattern applies to TLSPolicy and will apply to every new policy form and only the spec fields change.
Bidirectional Sync with js-yaml
The dual view only works if both views stay in sync. Kuadrant achieves this using the js-yaml library and React's useEffect.
Form → YAML: When the user changes any form field, a useEffect watches the state and rebuilds the YAML object automatically:
React.useEffect(() => {
setYamlInput(createDNSPolicy());
}, [policyName, selectedGateway, loadBalancing, healthCheck]);
Every time policyName or selectedGateway changes, createDNSPolicy() runs again and the YAML editor receives the updated object.
YAML → Form: When the user edits YAML directly, handleYAMLChange parses it back into form state:
const handleYAMLChange = (yamlInput: string) => {
const parsedYaml = yaml.load(yamlInput);
setPolicyName(parsedYaml.metadata?.name || '');
setSelectedGateway({
name: parsedYaml.spec?.targetRef?.name || '',
namespace: parsedYaml.metadata?.namespace || '',
});
};
The yaml.load() from js-yaml converts the YAML string into a JavaScript object, and each field is mapped back to its corresponding useState. So if a user changes metadata.name in the YAML editor, the Policy Name text field updates when they switch back to Form View.
This two-way sync is the hardest part of each policy form and every form field must have a mapping in both directions.
Why DNSPolicy and TLSPolicy Are the Blueprint
These two files are the architectural template for every future policy form:
KuadrantDNSPolicyCreatePage.tsx: The more complex reference with expandable sections for LoadBalancing and HealthCheck.
KuadrantTLSCreatePage.tsx: The simpler reference with radio toggle for ClusterIssuer and Issuer selection.
Every pattern described in this blog the Form/YAML toggle, createPolicy() builder, bidirectional sync, validation and edit mode comes from these two files.
Compare these to the current YAML only policies KuadrantOIDCPolicyCreatePage.tsx is nothing but a hardcoded YAML template and ResourceYAMLEditor. No form, no validation, no sync.
Reusable Components: The Building Blocks
The DNSPolicy and TLSPolicy forms don't build everything from scratch. They rely on shared components that any new policy form can reuse:
GatewaySelect
A dropdown that fetches all available Gateways from the cluster using useK8sWatchResource and lets the user select one. Since every policy needs a targetRef pointing to a Gateway, this component is used in every form.
KuadrantCreateUpdate
The shared Save/Cancel button logic. It handles calling k8sCreate for new policies and k8sUpdate for existing ones, displays error alerts if the API call fails and disables the Save button when form validation fails.
ExpandableSection
It is Used for optional fields that don't need to be visible by default.
These components mean that when building a new policy form, you don't start from zero. The Gateway selection, save logic and expandable sections are already built, you just import them.
What's Next: 5 Policies Need Forms
The remaining 5 policies currently only have a ResourceYAMLEditor with a hardcoded template. Each one needs to be transformed into a full form-based editor following the DNSPolicy/TLSPolicy blueprint.
Here's the breakdown ordered by complexity:
OIDCPolicy: Fields: policy name, target gateway, clientID, issuerURL. A good starting point with minimal state management.
TokenRateLimitPolicy: Fields: policy name, target gateway, limits with rates (limit and time window). Similar to OIDCPolicy but with a nested limits object.
PlanPolicy: Fields: policy name, target gateway, array of plans. Each plan has a tier, predicate and limits. Needs add/remove buttons for dynamic plan management.
RateLimitPolicy: Fields: policy name, target gateway, limits with rates, counters and conditions. Existing helper components (AddLimitModal, LimitSelect) can be reused here.
AuthPolicy: Fields: policy name, target gateway, authentication rules, authorization rules, response configuration. Multiple nested objects with many optional fields.
How I Would Approach It
Start with OIDCPolicy since it has the simplest spec, then progress to TokenRateLimitPolicy, PlanPolicy, RateLimitPolicy and finally AuthPolicy. Each policy would follow the same pattern. One PR per policy, reusing GatewaySelect and KuadrantCreateUpdate with form validation and bidirectional YAML sync.
Comments
Join the discussionNo comments yet. Be the first to comment.
