kubernetes / kubernetes/kompose

StatefulSet with kompose.volume.type=persistentVolumeClaim generates duplicate PVC artifacts

Open
#2,090 2 comments 0 reactions 0 assignees View on GitHub
lifecycle/rotten
Dominant language
Go
Stars
10.6k
Forks
816
PR merge metrics
No merged PRs in 30d

Description

## Describe the bug

When a service uses `kompose.controller.type: statefulset` together with `kompose.volume.type: persistentVolumeClaim`, `kompose convert` generates three artifacts for the same volume — two of which are redundant and cause a broken deployment:

1. `volumeClaimTemplates` inside the StatefulSet ✅ (correct — this is what the pod uses)
2. A standalone `-persistentvolumeclaim.yaml` ❌ (orphaned — no consumer, stays `Pending` forever)
3. A `spec.template.spec.volumes[]` entry referencing the same volume ❌ (redundant — conflicts with `volumeClaimTemplates`)

The pod binds to the PVC auto-created by `volumeClaimTemplates` (e.g. `pgdata-postgresql-0`), while the standalone `pgdata` PVC sits `Pending` indefinitely with no consumer.

## To Reproduce

Docker Compose service with these labels:

```yaml
services:
postgresql:
image: postgres:13-alpine
volumes:
- pgdata:/var/lib/postgresql/data
labels:
kompose.controller.type: statefulset
kompose.volume.size: 1Gi
kompose.volume.type: persistentVolumeClaim

volumes:
pgdata:
```

Run:

```sh
kompose convert -c -f docker-compose.yaml -o my-chart
```

## Expected behavior

For a StatefulSet, the volume should be managed exclusively by `volumeClaimTemplates`. kompose should:
- Emit `volumeClaimTemplates` in the StatefulSet ✅
- **Not** emit a standalone `pgdata-persistentvolumeclaim.yaml`
- **Not** add a `spec.template.spec.volumes[]` entry for the same volume (it is owned by `volumeClaimTemplates`)

## Actual behavior

Three files/entries are generated for the same volume. Deploying to Kubernetes results in an orphaned PVC stuck in `Pending` and the StatefulSet failing due to the conflicting `spec.volumes` entry.

## Workaround

```sh
# Remove redundant spec.volumes entry
yq -i 'del(.spec.template.spec.volumes[] | select(.name == "pgdata"))' \
my-chart/templates/postgresql-statefulset.yaml

# Delete orphaned standalone PVC manifest
rm -f my-chart/templates/pgdata-persistentvolumeclaim.yaml
```

## Environment

- kompose version: `1.38.0 (a8f5d1cbd)`
- Kubernetes: kind cluster
- OS: Linux

## Root cause (suspected)

`ConfigVolumes` in `pkg/transformer/kubernetes/kubernetes.go` unconditionally emits standalone `PersistentVolumeClaim` objects regardless of the target controller type. The StatefulSet path correctly generates `volumeClaimTemplates`, but `ConfigVolumes` is not suppressed for the StatefulSet case, leading to both artifacts being emitted simultaneously.

This was introduced with StatefulSet support in [PR #1452](https://github.com/kubernetes/kompose/pull/1452).

Contributor guide

Open the contributing guide

Research direction

Read pkg/transformer/kubernetes/kubernetes.go, starting with ConfigVolumes and the StatefulSet generation path. Reproduce the issue with the supplied Compose labels and kompose convert command; done means only the StatefulSet volumeClaimTemplates remains, with no standalone PVC or duplicate pod volume entry.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker-compose, go, kubernetes
Domain
devops, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.