Skip to content

Fix Kubernetes Label Validation Error for Parent Stack Values#163

Merged
smecsia merged 7 commits into
mainfrom
staging
Feb 21, 2026
Merged

Fix Kubernetes Label Validation Error for Parent Stack Values#163
smecsia merged 7 commits into
mainfrom
staging

Conversation

@universe-ops

Copy link
Copy Markdown
Contributor

Problem

Kubernetes deployments were failing with label validation errors when parent stack values contained forward slashes (e.g., /demo/root):

stderr: error: Preview failed: 1 error occurred:
* the Kubernetes API server reported that "likeclaw" failed to fully initialize or become live: Namespace "likeclaw" is invalid: metadata.labels: Invalid value: "/demo/root": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character

Solution

  • Added sanitizeK8sLabelValue() function to properly sanitize Kubernetes label values according to RFC requirements
  • Applied sanitization to parent stack labels (LabelParentStack, LabelClientStack, LabelParentEnv) to ensure compliance
  • Handles common cases like stack paths with forward slashes by converting them to hyphens

Technical Changes

  • New function: sanitizeK8sLabelValue() in pkg/clouds/pulumi/kubernetes/simple_container.go
    • Replaces forward slashes with hyphens
    • Removes invalid characters while preserving alphanumeric, -, _, .
    • Ensures labels start/end with alphanumeric characters
    • Provides fallback for empty results
  • Updated label assignments to use sanitization for parent stack values

Additional Improvements

  • Enhanced GitHub Actions submodule handling with better git configuration for dubious ownership errors
  • Added Caddy staging image build to CI/CD pipeline alongside GitHub Actions image
  • Optimized CI runner resources from 32vcpu to 8vcpu for cost efficiency
  • Minor formatting fixes in workflow files

Impact

  • Fixes deployment failures caused by invalid Kubernetes label values
  • Maintains label readability while ensuring compliance (e.g., /demo/rootdemo-root)
  • Backward compatible - existing valid labels remain unchanged
  • Improved CI/CD reliability with better submodule and image handling

Testing

  • All builds pass successfully
  • Linters clean (0 issues)
  • Function handles edge cases (empty values, special characters, etc.)

@smecsia
smecsia merged commit dd372bd into main Feb 21, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants