ConfigMap Validation
Tekton Pruner uses a ValidatingWebhook to ensure ConfigMaps meet required specifications before they are created or updated in the cluster. This document explains how the validation works and what requirements must be met.
TOC
Overview
The pruner webhook validates ConfigMaps to:
- Enforce required labels and naming conventions
- Prevent invalid configurations from being applied
- Protect against accidental deletion of critical configs
- Ensure namespace-level configs respect global boundaries
How Validation Works
The validation webhook is automatically installed with pruner and intercepts ConfigMap CREATE, UPDATE, and DELETE operations. It only validates ConfigMaps with the label app.kubernetes.io/part-of: tekton-pruner, ensuring regular ConfigMaps in your cluster are unaffected.
Validation Rules
1. Required Labels
All pruner ConfigMaps MUST have these labels:
Validation checks:
- Both labels must be present
app.kubernetes.io/part-ofmust equaltekton-prunerpruner.tekton.dev/config-typemust be eitherglobalornamespace
Error example:
2. Selector Restrictions
CRITICAL: Selectors (matchLabels/matchAnnotations) are ONLY supported in namespace-level ConfigMaps (tekton-pruner-namespace-spec), NOT in global ConfigMaps.
Valid - Selectors in Namespace ConfigMap:
Invalid - Selectors in Global ConfigMap:
Error example:
Why this restriction?
- Selector-based resource matching requires access to the resource's labels/annotations at runtime
- Global ConfigMaps are designed for cluster-wide defaults, not resource-specific matching
- Namespace ConfigMaps provide the correct scope for dynamic resource selection
See also: Resource Groups for selector usage examples
3. Naming Requirements
Global Config:
- Name: Must be
tekton-pruner-default-spec(fixed) - Namespace: Must be
tekton-pipelines(or system namespace) - Label:
pruner.tekton.dev/config-type: global
Namespace Config:
- Name: Must be
tekton-pruner-namespace-spec(fixed) - Namespace: Must be in a user namespace (NOT in system or tekton namespaces)
- Label:
pruner.tekton.dev/config-type: namespace
Error examples:
3. Namespace Restrictions
Forbidden namespaces for namespace-level configs:
- System namespaces:
kube-* - Tekton namespaces:
tekton-pipelines,tekton-*
Attempting to create a namespace-level config in these locations will be rejected.
Error example:
4. Configuration Content Validation
The webhook validates configuration data including:
- Time values: ttlSecondsAfterFinished must be non-negative
- History limits: historyLimit, successfulHistoryLimit, and failedHistoryLimit must be non-negative and cannot exceed global maximums if enforced
- Selectors (namespace ConfigMaps only): Label and annotation selectors must have valid key-value pairs; name selectors must be valid resource names
Note: Selectors (pipelineRuns, taskRuns arrays with matchLabels/matchAnnotations) are only processed in namespace-level ConfigMaps. They are ignored in global ConfigMaps.
5. Deletion Protection
The webhook prevents deletion of the global config if namespace-level configs still exist. You must delete all namespace configs before deleting the global config. Namespace configs can be deleted without restrictions.
6. Global Config Enforcement
When creating or updating namespace-level configs, the webhook fetches the global config and validates that namespace values do not exceed global maximums if defined (e.g., maxTTLSecondsAfterFinished, maxHistoryLimit).
Common Validation Errors
Missing Labels Error
Solution: Add the required labels to your ConfigMap:
Wrong Config Type Error
Solution: Use only global or namespace as config-type values.
Wrong Name Error
Solution: Use the exact required name:
- Global:
tekton-pruner-default-spec - Namespace:
tekton-pruner-namespace-spec
Exceeds Global Limit Error
Solution: Reduce the namespace value to be within global limits, or request admin to increase global maximum.
Deletion Blocked Error
Solution: Delete all namespace configs first:
Troubleshooting
Verify Webhook Status
Test Validation
Create an invalid ConfigMap to verify webhook is functioning:
Expected error: admission webhook denied the request: Invalid pruner ConfigMap labels
Bypassing Validation (Not Recommended)
Warning: Bypassing validation can lead to misconfigured pruner behavior and should only be done in emergency situations.
To temporarily bypass validation:
-
Remove the identifying label:
-
Make necessary changes
-
Re-add the label:
Note: The pruner controller will not process ConfigMaps without proper labels.
Best Practices
- Always include required labels from the start
- Use exact naming conventions for global and namespace configs
- Test configurations in a non-production namespace first
- Check validation errors carefully - they indicate what needs to be fixed
- Monitor webhook logs when rolling out new configurations
- Delete namespace configs before attempting to delete global config