:8080 metrics port collision when starting a new init controller for a different WorkspaceType

Open Beginner friendly
#26 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
go
Domain
backend

Research direction

Start in internal/controller/targetcontroller/controller.go at createMulticlusterManager and inspect how the primary and subsequent managers configure metrics. Reproduce the second InitTarget scenario with different WorkspaceTypes, then verify that the new init controller starts without a :8080 bind collision and handles the target.

Written by the indexing model from the issue text.

Description

Bug

When init-agent picks up an InitTarget pointing at a WorkspaceType it hasn't seen yet, `targetcontroller` calls `createMulticlusterManager()` which calls `mcmanager.New(wstConfig, provider, manager.Options{Scheme: scheme})` without specifying `Metrics.BindAddress`. controller-runtime defaults to `:8080`, which is already in use by the FIRST manager.

Result: the new init controller fails to start with:

```
Failed to run multicluster manager ctrlkey=root:account error=failed to start metrics server: failed to create listener: listen tcp :8080: bind: address already in use
```

The new InitTarget is effectively ignored until the pod restarts (and it happens to start with that target already known).

Reproduction
  1. Run init-agent with one InitTarget A targeting WT `foo`.
  2. Apply a second InitTarget B targeting WT `bar`.
  3. init-agent's targetcontroller logs "Creating new init controller…" and then crashes the new manager on port collision.
Suggested fix

In `internal/controller/targetcontroller/controller.go` `createMulticlusterManager`, set `manager.Options{ ..., Metrics: metricsserver.Options{BindAddress: "0"} }` for all subsequent managers, OR allocate distinct ports automatically. Only the primary manager needs metrics.

Environment
  • init-agent: main, commit 6ad35e2
Dominant language
Go
Stars
0
Forks
5
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from kcp-dev/init-agent

All issues in kcp-dev/init-agent

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.