Skip to content

Certificate, Issuer, and ServiceAccount processors ignore -preserve-ns flag #192

@girdharshubham

Description

@girdharshubham

Bug

The -preserve-ns flag is supposed to preserve the original namespace in generated Helm templates, but several processors silently drop the namespace because they use hardcoded templates instead of the shared ProcessObjMeta helper.

Affected Processors

  • pkg/processor/webhook/cert.go — Certificate
  • pkg/processor/webhook/issuer.go — Issuer
  • pkg/processor/rbac/serviceaccount.go — ServiceAccount

These processors build their metadata using inline format strings that never include a namespace field, regardless of the -preserve-ns flag.

All other processors (Deployment, DaemonSet, StatefulSet, ConfigMap, Secret, Service, Ingress, Role, RoleBinding, ClusterRoleBinding, Job, CronJob, PDB, PVC, and the default processor) use ProcessObjMeta which correctly respects -preserve-ns.

Reproduction

Given a Certificate with an explicit namespace:

apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: my-cert
  namespace: my-system
spec:
  dnsNames:
  - my-service.my-system.svc
  issuerRef:
    kind: Issuer
    name: my-issuer
  secretName: my-cert

Running:

cat cert.yaml | helmify -preserve-ns mychart

Expected: The generated template includes namespace: my-system in metadata.

Actual: The namespace is silently dropped from the generated template.

Suggested Fix

Refactor Certificate, Issuer, and ServiceAccount processors to use ProcessObjMeta for metadata generation instead of hardcoded templates. This would give them namespace, label, and annotation handling for free and ensure consistency with all other processors.

The cert-manager-specific behavior (helm hook annotations when -cert-manager-as-subchart is set, webhook conditional wrapping when -add-webhook-option is set) can be layered on after the ProcessObjMeta call via string manipulation on the returned metadata string.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions