Add or remove a shared resource type
Shared resources are the lists below the workload tabs (ConfigMaps, Secrets, PVCs, etc.).
This guide walks through adding a new type and removing an existing one.
Add a resource typeโ
Example: add a NetworkPolicy list.
You touch three files: baseline.js, App.jsx, and toValues.js. Optionally a Helm template too.
Step 1 โ describe it in baseline.jsโ
Add an entry to resourceSections[]:
// ui/docs/src/app/charts/baseline.js โ resourceSections[]
{
key: 'networkPolicies',
label: '๐ Network Policies',
tip: 'NetworkPolicies applied with this release',
addLabel: 'NetworkPolicy',
stateKey: 'networkPolicies',
nextIdKey: 'netpolNext',
createItem: (id) => ({ id, name: '', yaml: '' }),
fields: [
{ key: 'name', label: 'Name', type: 'text', placeholder: 'allow-ingress' },
{
key: 'yaml',
label: 'NetworkPolicy spec (YAML)',
type: 'yaml',
rows: 5,
placeholder: 'podSelector: {}\ningress:\n - from:\n - podSelector: {}',
},
],
},
The ResourceList component renders it automatically โ no JSX changes needed.
Step 2 โ add state in App.jsxโ
// Add useState declarations
const [networkPolicies, setNetworkPolicies] = useState([])
const [netpolNext, setNetpolNext] = useState(0)
Pass them to ResourceList the same way existing resources are wired (look at how configMaps/setConfigMaps/cmNext/setCmNext are passed).
Add to the toValues() call and useMemo dep array:
const values = useMemo(() => toValues({
workloads, configMaps, secrets, sealedSecrets, pvcs,
networkPolicies, // โ add
global, persistentVolumes, extraManifests,
}), [...deps, networkPolicies])
Add prefill in prefillFromValues():
networkPolicies: (v.networkPolicies || []).map((np, i) => ({
id: i,
name: np.name || '',
yaml: dumpOrEmpty({
podSelector: np.podSelector,
ingress: np.ingress,
egress: np.egress,
}),
})),
Also wire the setter in handleApplyUpload:
setNetworkPolicies(state.networkPolicies)
setNetpolNext(state.networkPolicies.length)
Step 3 โ emit in toValues.jsโ
Add to the destructure:
export function toValues(state) {
const { workloads, configMaps, secrets, sealedSecrets, pvcs,
networkPolicies, // โ add
global, persistentVolumes, extraManifests } = state
Add the emit block:
const netpolList = (networkPolicies || [])
.filter(np => np.name.trim())
.map(np => clean({ name: np.name, ...parseYaml(np.yaml) }))
.filter(Boolean)
if (netpolList.length) values.networkPolicies = netpolList
Step 4 โ add the Helm templateโ
Create base-chart/templates/networkpolicy.yaml:
{{- range .Values.networkPolicies }}
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ .name }}
labels:
app.kubernetes.io/instance: {{ $.Release.Name }}
app.kubernetes.io/managed-by: {{ $.Release.Service }}
spec:
{{- omit . "name" | toYaml | nindent 2 }}
{{- end }}
Remove a resource typeโ
Example: remove SealedSecrets.
Step 1 โ remove from baseline.jsโ
Delete the entry with key: 'sealedSecrets' from resourceSections[].
Step 2 โ remove state from App.jsxโ
- Delete
const [sealedSecrets, setSealedSecrets] = useState([]) - Delete
const [ssNext, setSsNext] = useState(0) - Remove
sealedSecretsfrom thetoValues()call anduseMemodep array - Remove
sealedSecretsfromprefillFromValues()return value - Remove the setter calls from
handleApplyUpload
Step 3 โ remove from toValues.jsโ
- Remove
sealedSecretsfrom the destructure - Delete the
ssListemit block
Step 4 โ delete the Helm templateโ
rm base-chart/templates/sealedsecret.yaml
Checklistโ
Adding a resource typeโ
- Entry in
resourceSections[]inbaseline.js -
useState+ counter inApp.jsx - Pass state + setter to
ResourceListinApp.jsx - Add to
toValues()call anduseMemodeps inApp.jsx - Prefill in
prefillFromValues()and setter inhandleApplyUploadinApp.jsx - Emit block in
toValues.js - Helm template in
base-chart/templates/
Removing a resource typeโ
- Delete entry from
resourceSections[]inbaseline.js - Remove
useState+ counter fromApp.jsx - Remove from
toValues()call anduseMemodeps - Remove from
prefillFromValues()andhandleApplyUploadinApp.jsx - Remove emit block from
toValues.js - Delete Helm template