ashupednekar / ashupednekar/compose

_⚠️ Potential issue_ | _🔴 Critical_

Open
#8 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Description

_⚠️ Potential issue_ | _🔴 Critical_

**Critical: Port mapping logic loses service port information.**

Lines 143-164 handle port and targetPort extraction, but lines 154-160 unconditionally overwrite `portInfo.Port` with `targetPort` when it exists. In Kubernetes:
- `port`: The port exposed by the Service (external/cluster-facing)
- `targetPort`: The port on the container/pod (internal)

For Docker Compose, you typically need both to create mappings like `servicePort:targetPort`. This logic discards the service port.

Apply this diff to preserve both port values:

```diff
+ portInfo := spec.PortInfo{}
+ servicePort := 0
+
if port, exists := portMap["port"]; exists {
if portInt, ok := port.(int); ok {
- portInfo.Port = portInt
+ servicePort = portInt
} else if portStr, ok := port.(string); ok {
if p, err := strconv.Atoi(portStr); err == nil {
- portInfo.Port = p
+ servicePort = p
}
}
}

if targetPort, exists := portMap["targetPort"]; exists {
if targetPortInt, ok := targetPort.(int); ok {
portInfo.Port = targetPortInt
} else if targetPortStr, ok := targetPort.(string); ok {
if tp, err := strconv.Atoi(targetPortStr); err == nil {
portInfo.Port = tp
}
}
} else {
- // If targetPort is not specified, it defaults to port
- portInfo.Port = portInfo.Port
+ // If targetPort is not specified, use service port as target
+ portInfo.Port = servicePort
}
```

**Note:** Verify if `spec.PortInfo` needs an additional field for the service port, or if the current structure is sufficient for your use case.

> Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents

```
In pkg/charts/parse.go around lines 143 to 164, the current logic overwrites
portInfo.Port with targetPort, losing the service/exposed port; change the
extraction so you preserve both values: assign the service-facing value (from
port) to a distinct field (e.g., portInfo.ServicePort or keep portInfo.Port if
that represents the service port) and assign the container-facing value (from
targetPort) to a separate field (e.g., portInfo.TargetPort); update the parsing
branches to set ServicePort when port exists and TargetPort when targetPort
exists (parsing ints/strings as before) and do not overwrite the service port
with targetPort; also verify and, if necessary, add the new
ServicePort/TargetPort fields to spec.PortInfo to match usage.
```

_Originally posted by @coderabbitai[bot] in https://github.com/ashupednekar/compose/pull/7#discussion_r2388769263_

Contributor guide

No contributing guide indexed for this repository

Research direction

Read pkg/charts/parse.go around lines 143-164 and inspect spec.PortInfo to determine how port and targetPort are represented. Trace the parsing entry point and check existing tests or usages of PortInfo. Done means the service-facing and container-facing values are both preserved without targetPort overwriting the service port.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker-compose, go, kubernetes
Domain
devops, infrastructure
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.