kubernetes-sigs / kustomize

Customization of kubernetes YAML configurations
Apache License 2.0
10.7k stars 2.22k forks source link

Using nameSuffix is applied to everything but spec/template/spec/volumes/persistentVolumeClaim/claimName of a deployment #5690

Open svscorp opened 1 month ago

svscorp commented 1 month ago

What happened?

I'm using Kustomize v5.2.1, and trying to add environment related suffix (i.e. -prod, -dev) using nameSuffix in overlays. When I deploy the configuration, I see resources such as pvc, service are properly deployed with the right naming (i.e. grafana-prod), but my deployment can't start, because it can't find the pvc with name "grafana".

My configuration: base/grafana-persistentvolumeclaim.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: grafana
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: longhorn
  resources:
    requests:
      storage: 2Gi`

base/grafana-deployment.yaml
`apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    service: grafana
  name: grafana
  namespace: observability
spec:
  replicas: 1
  selector:
    matchLabels:
      service: grafana
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        network/backend: "true"
        service: grafana
    spec:
      containers:
        - image: grafana/grafana:10.4.2-ubuntu
          name: grafana
          resources: {}
          volumeMounts:
            - mountPath: /var/lib/grafana
              name: grafana
      restartPolicy: Always
      volumes:
        - name: grafana
          persistentVolumeClaim:
            claimName: grafana
status: {}

base/kustomization.yaml

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- grafana-deployment.yaml
- grafana-service.yaml
- grafana-persistentvolumeclaim.yaml
- longhorn-storageclass.yaml

base/grafana-deployment.yaml (omitted, it's ok)
base/longhorn-storageclass.yaml (omitted, it's ok)

overlays/prod/kustomization.yaml

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
nameSuffix: -prod

resources:
  - ../../base

P.S> Also tried this approach, but this didn't work either https://github.com/kubernetes-sigs/kustomize/blob/master/examples/transformerconfigs/README.md P.S2> Using transformers, placed into the overlays like this - worked. But for me it looks like a workaround...

apiVersion: builtin
kind: PrefixSuffixTransformer
metadata:
  name: suffix-transformer
suffix: "-prod" 
fieldSpecs:
  - path: spec/volumes/persistentVolumeClaim/claimName
    kind: Deployment
  - path: spec/template/spec/volumes/persistentVolumeClaim/claimName
    kind: Deployment

What did you expect to happen?

I was expecting, that nameSuffix will be properly applied and the claimName of the PVC in deployment template would also become suffixed with "-prod".

How can we reproduce it (as minimally and precisely as possible)?

The configuration can be used, as I wrote in the previous section.

Expected output

No response

Actual output

No response

Kustomize version

5.2.1

Operating system

None

stormqueen1990 commented 1 month ago

Similar to #5674, this would require adding the missing path into api/internal/konfig/builtinpluginconsts/namereference.go, along with a test case in api/krusty/namereference_test.go.

Sample PR: https://github.com/kubernetes-sigs/kustomize/pull/5698

/triage accepted /help

k8s-ci-robot commented 1 month ago

@stormqueen1990: This request has been marked as needing help from a contributor.

Guidelines

Please ensure that the issue body includes answers to the following questions:

For more details on the requirements of such an issue, please see here and ensure that they are met.

If this request no longer meets these requirements, the label can be removed by commenting with the /remove-help command.

In response to [this](https://github.com/kubernetes-sigs/kustomize/issues/5690): >Similar to #5674, this would require adding the missing path into `api/internal/konfig/builtinpluginconsts/namereference.go`, along with a test case in `api/krusty/namereference_test.go`. > >Sample PR: https://github.com/kubernetes-sigs/kustomize/pull/5698 > >/triage accepted >/help Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.