kustomize: Regression: PatchTransformer alters the name of ports that have matching containerPort values
When a deployment has a container with two differently-named ports that match on the containerPort, a PatchTransformer alters the name of the second port so that it matches the first.
Affected versions
{Version:kustomize/v3.8.0 GitCommit:6a50372dd5686df22750b0c729adaf369fbf193c BuildDate:2020-07-05T14:08:42Z GoOs:linux GoArch:amd64}
and
{Version:kustomize/v3.8.1 GitCommit:0b359d0ef0272e6545eda0e99aacd63aef99c4d0 BuildDate:2020-07-16T00:58:46Z GoOs:linux GoArch:amd64}
Test setup
kustomization.yaml
resources:
- resources.yaml
transformers:
- transformers.yaml
resources.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-deployment
spec:
template:
spec:
containers:
- image: test-image
name: test-deployment
ports:
- containerPort: 8080
name: take-over-the-world
protocol: TCP
- containerPort: 8080
name: disappearing-act
protocol: TCP
transformers.yaml
---
apiVersion: builtin
kind: PatchTransformer
metadata:
name: test-transformer
patch: |-
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-transformer
labels:
test-transformer: did-my-job
target:
kind: Deployment
name: test-deployment
Expected behavior
This is the behavior seen in v3.7.0. The two port entries have distinct names, reflecting their definitions in resources.yaml.
$ ./kustomize-v3.7.0 version
{Version:kustomize/v3.7.0 GitCommit:42d1f7b792a80af34828ec4c89af99e1043351a7 BuildDate:2020-07-04T19:15:46Z GoOs:linux GoArch:amd64}
$ ./kustomize-v3.7.0 build .
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
test-transformer: did-my-job
name: test-deployment
spec:
template:
spec:
containers:
- image: test-image
name: test-deployment
ports:
- containerPort: 8080
name: take-over-the-world
protocol: TCP
- containerPort: 8080
name: disappearing-act
protocol: TCP
$
Actual behavior
This is the behavior seen in v3.8.0 and v3.8.1. The two port entries have matching names.
$ ./kustomize-v3.8.1 version
{Version:kustomize/v3.8.1 GitCommit:0b359d0ef0272e6545eda0e99aacd63aef99c4d0 BuildDate:2020-07-16T00:58:46Z GoOs:linux GoArch:amd64}
$ ./kustomize-v3.8.1 build .
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
test-transformer: did-my-job
name: test-deployment
spec:
template:
spec:
containers:
- image: test-image
name: test-deployment
ports:
- containerPort: 8080
name: take-over-the-world
protocol: TCP
- containerPort: 8080
name: take-over-the-world
protocol: TCP
$
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 22 (21 by maintainers)
Commits related to this issue
- add test for issue #2767 — committed to hornpolish/kustomize by deleted user 4 years ago
For posterity…
With the arrival of #3159, the test case now drops disappearing-act. The behavior is expected, given the discussions and the corresponding implementation. The test case results now are:
@ephesused Yes I expect that result. Since the merge key problem hasn’t been fixed. @natasha41575 is working on a solution with modified schema.
Top of the list https://github.com/kubernetes-sigs/kustomize/projects/2
What about cases with multiple protocols that use the same port number (an example from consul)? Is there a workaround?