Aleksei Sviridkin 7be083a5a7 feat(harbor): expose replicas and zone spread for the request path (#4880)
<!-- Thank you for making a contribution! Here are some tips for you:
- Use Conventional Commits for the PR title: `type(scope): description`
- If it's a work in progress, consider creating this PR as a draft.
-->

## What this PR does

Closes #4824.

Every `docker login`, pull and push goes through nginx → core
(`/service/token`) → registry, and each of them ran as a single pod.
Losing the node that hosted one stopped all registry traffic, however
many PostgreSQL and Redis instances backed it. The vendored goharbor
chart already scales these components and the registry keeps its blobs
in S3, so only the wrapper was missing the knobs.

**Request path (`packages/apps/harbor`)**

- New `nginx.replicas`, `portal.replicas`, `core.replicas` and
`registry.replicas`, all defaulting to `1`.
- Above one replica, the wrapper forwards to the upstream chart a
`podDisruptionBudget` with `maxUnavailable: 1` and
`topologySpreadConstraints`. Upstream defaults `minAvailable` to 1 and
renders whichever of the two fields is set, and the API server rejects a
PDB carrying both, so the wrapper forwards `minAvailable: 0` to drop it.
- At one replica nothing but `replicas: 1` is forwarded, which is the
upstream default, so an existing install renders the same Deployments as
before.
- The `WorkloadMonitor`s for core, registry and portal take `replicas`
from the values instead of a hard-coded `1`. `minReplicas` stays at 1,
since one serving replica is enough for the component to work.

- The spread follows the platform's
`scheduling.globalAppTopologySpreadConstraints` (read from
`_cluster.scheduling`), as postgres, etcd, keycloak, grafana and
kubernetes-nodes already do, so the cluster operator sets the policy
once. When the platform sets none, a soft spread stands in: zone then
hostname, both `ScheduleAnyway`, so a cluster without zone labels or
with fewer nodes than replicas still schedules every replica. Any
`labelSelector` in the policy is dropped, because the upstream chart
appends its own `release`/`app`/`component` selector to every entry.

**Data tier (`packages/system/harbor`)**

- The CNPG `Cluster` (when `database.replicas > 1`) gets
`topologySpreadConstraints` from the same platform policy, or a
`ScheduleAnyway` zone spread when the platform sets none; CNPG's default
anti-affinity handles nodes. The Redis pods and sentinels already spread
hard per node on main (#4990); this adds a `ScheduleAnyway` zone spread
on top of that default. A constraint in the platform policy without a
selector gets the component's own; a selector the policy sets is kept,
as in the keycloak chart.

**Deviations from the issue, on purpose**

- Placement follows the platform-wide
`globalAppTopologySpreadConstraints` instead of a set of rules
hard-coded in Harbor, to stay consistent with the other applications.
The fallback spreads across nodes with a `topologySpreadConstraints`
entry rather than a preferred `podAntiAffinity` term: the upstream chart
appends its own selector to spread entries, while an affinity term is
passed through verbatim and would have to hard-code that label set in
the wrapper.
- On the data tier the zone spread goes through
`topologySpreadConstraints`, not `affinity.topologyKey:
topology.kubernetes.io/zone`. Moving CNPG's `topologyKey` to the zone
would drop its per-node anti-affinity, so instances could share a node
on a cluster without zone labels. With spread constraints the two add
up, and for Redis the zone entry sits beside the per-node one.
- `jobservice.replicas` (item 5 of the issue, which needs `jobLoggers:
[database]`) is left for a follow-up, as the issue suggests.

**Upgrade impact**

- Request path: none at the default replica count.
- Data tier: `database.replicas` and `redis.replicas` default to 2, so
on upgrade most installs see a one-off rolling restart of the CNPG
instances (with a switchover), of the Redis pods and of the sentinels,
as their pod spec gains the spread constraint. Where the platform policy
uses `DoNotSchedule`, it is now enforced for Harbor pods too, as it
already is for the other applications.

**Tests**

- `packages/apps/harbor/tests/replica_placement_test.yaml`: defaults
forward nothing beyond `replicas: 1`; above one replica the PDB and
spread are forwarded; the platform policy replaces the fallback and
loses its `labelSelector`, and is ignored at one replica; components
scale independently; `registry.replicas` lands at the Deployment level,
not under `registry.registry`; WorkloadMonitors follow the values.
- `packages/system/harbor/tests/zone_spread_test.yaml`: CNPG, Redis and
sentinel spread with the right selectors and no `affinity` override,
both with the fallback and with a multi-entry platform policy, keeping a
selector the policy sets; `redis_spread_test.yaml` covers the per-node
default with the zone entry on top; and, rendering the vendored chart
with the values the wrapper forwards, the PDB carries `maxUnavailable`
alone and the spread entries are scoped to the component's pods.
- Checked that the tests fail with the fix removed (helper without
`minAvailable: 0`, upstream PDB without the zeroing, CNPG spread
removed, platform policy ignored). `helm unittest` on both charts: 72/72
passing. Also rendered the app chart, with and without a platform
policy, fed its HelmRelease values into the system chart, and checked
the resulting Deployments, PDBs and CNPG `Cluster`.

### Screenshots

No UI change.

### Downstream repositories

- [ ] No downstream repository is affected by this change
- [ ] [cozystack/website](https://github.com/cozystack/website) -
follow-up:
- [x]
[cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack)
- follow-up: cozystack/terraform-provider-cozystack#70 (issue: the
provider models Harbor by hand)
- [ ]
[cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack)
- follow-up:
- [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up:
- [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up:
- [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) -
follow-up:
- [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) -
follow-up:
- [ ]
[cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server)
- follow-up:
- [ ]
[cozystack/external-apps-example](https://github.com/cozystack/external-apps-example)
- follow-up:
- [ ] [cozystack/examples](https://github.com/cozystack/examples) -
follow-up:
- [ ] [cozystack/community](https://github.com/cozystack/community) -
follow-up:

The diff adds fields to the `harbor` app's `values.schema.json`, which
the Terraform provider models by hand, so a follow-up issue is open
there. The website reference page is regenerated from the README on
release, and no other trigger in the map matches the diff.

### Release note

```release-note
feat(harbor): nginx, portal, core and registry now take a `replicas` value. Above one replica they get a PodDisruptionBudget and follow the platform's `globalAppTopologySpreadConstraints`, or a best-effort spread across zones and nodes when none is set, so draining or losing a node or zone keeps docker login, pull and push working. The PostgreSQL and Redis instances and the Redis sentinels now follow the same policy, or a best-effort zone spread; on upgrade this causes a one-off rolling restart of the database and Redis pods.
```


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **New Features**
* Harbor NGINX, portal, core, and registry replica counts are
configurable and default to one. Above one replica, these components use
a PodDisruptionBudget and follow platform-wide placement settings when
available, or spread across zones and nodes otherwise.
* Database replicas spread according to placement settings when
configured above one. Redis replicas also spread above one, while all
three Redis sentinels are always spread.
* Core and registry resource settings now use a shared default when not
specified.
* **Documentation**
* Harbor configuration guidance now describes replica settings,
placement behavior, and PodDisruptionBudget behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-27 01:52:06 +03:00
2026-11-04 00:56:56 +01:00
2025-10-08 09:43:34 +05:00
2024-02-08 12:04:32 +01:00

Cozystack Cozystack

GitHub Release Apache-2.0 License Commit activity OpenSSF Best Practices OpenSSF Scorecard CLOMonitor Support

Cozystack

Cozystack is a free and open-source platform and framework for building clouds.

Cozystack is a CNCF Sandbox project that was originally built and sponsored by Ænix.

With Cozystack, you can transform a bunch of servers into an intelligent system with a simple REST API for spawning Kubernetes clusters, Database-as-a-Service, virtual machines, load balancers, HTTP caching services, and other services with ease.

Use Cozystack to build your own cloud or provide a cost-effective development environment.

Cozystack user interface

Use-Cases

Documentation

The documentation is located on the cozystack.io website.

Read the Getting Started section for a quick start.

If you encounter any difficulties, start with the troubleshooting guide and work your way through the process that we've outlined.

Versioning

Versioning adheres to the Semantic Versioning principles.
A full list of the available releases is available in the GitHub repository's Release section.

Contributions

Contributions are highly appreciated and very welcomed!

In case of bugs, please check if the issue has already been opened by checking the GitHub Issues section. If it isn't, you can open a new one. A detailed report will help us replicate it, assess it, and work on a fix.

You are welcome to take on the fix yourself. Commits are used to generate the changelog, and their author will be referenced in it.

If you have a concrete feature request, open an issue. For a cross-cutting or architectural change, open a design proposal in the community repo. For questions or early ideas, use GitHub Discussions. See CONTRIBUTING.md for the full routing.

Community

You are welcome to join us in #cozystack, on either CNCF Slack (get an invite) or Kubernetes Slack (get an invite), in our Telegram group, and at our community meetings. Add them to your Google Calendar or iCal for convenience.

Project documents

Document What it covers
Governance How decisions are made and who makes them
Contributor Ladder How to grow from contributor to maintainer
Maintainers Who maintains the project
Code of Conduct What we expect of each other
Security Policy Reporting a vulnerability, and which releases get fixes
Adopters Who runs Cozystack in production
Roadmap Where the project is going

License

Cozystack is licensed under Apache 2.0.
The code is provided as-is with no warranties.

Commercial Support

A list of companies providing commercial support for this project can be found on official site.

Languages
Go 53.1%
Shell 33%
TypeScript 6.8%
Go Template 4.6%
Makefile 1.3%
Other 1.1%