Skip to content

Commit ee9289b

Browse files
fix(harbor): refuse request-path replica counts below one
nginx, portal, core and registry replicas were plain integers, so the schema accepted 0, which scales every docker login, pull and push away while the WorkloadMonitor still expects one pod, and negative values, which fail the nested HelmRelease at the apiserver. Bound all four to a minimum of 1 and cover the rejection in the unit tests. Assisted-by: LLM Signed-off-by: Mattia Eleuteri <[email protected]>
1 parent 71ca28a commit ee9289b

5 files changed

Lines changed: 55 additions & 5 deletions

File tree

‎api/apps/v1alpha1/harbor/types.go‎

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/apps/harbor/tests/replica_placement_test.yaml‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,41 @@ tests:
240240
asserts:
241241
- notExists:
242242
path: spec.values.harbor.core.topologySpreadConstraints
243+
244+
# Zero would scale the request path away, and a negative count would fail the
245+
# nested HelmRelease at the apiserver; the schema refuses both up front.
246+
- it: rejects zero nginx replicas
247+
template: templates/harbor.yaml
248+
set:
249+
nginx:
250+
replicas: 0
251+
asserts:
252+
- failedTemplate:
253+
errorPattern: "/nginx/replicas.: minimum: got 0, want 1"
254+
255+
- it: rejects zero portal replicas
256+
template: templates/harbor.yaml
257+
set:
258+
portal:
259+
replicas: 0
260+
asserts:
261+
- failedTemplate:
262+
errorPattern: "/portal/replicas.: minimum: got 0, want 1"
263+
264+
- it: rejects zero core replicas
265+
template: templates/harbor.yaml
266+
set:
267+
core:
268+
replicas: 0
269+
asserts:
270+
- failedTemplate:
271+
errorPattern: "/core/replicas.: minimum: got 0, want 1"
272+
273+
- it: rejects negative registry replicas
274+
template: templates/harbor.yaml
275+
set:
276+
registry:
277+
replicas: -1
278+
asserts:
279+
- failedTemplate:
280+
errorPattern: "/registry/replicas.: minimum: got -1, want 1"

‎packages/apps/harbor/values.schema.json‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
"replicas": {
3838
"description": "Number of replicas of the proxy every `docker login`, pull and push goes through. Above 1, adds a PodDisruptionBudget and spreads the replicas by the platform's `globalAppTopologySpreadConstraints`, or softly across zones and nodes when it is unset.",
3939
"type": "integer",
40-
"default": 1
40+
"default": 1,
41+
"minimum": 1
4142
}
4243
}
4344
},
@@ -49,7 +50,8 @@
4950
"replicas": {
5051
"description": "Number of web portal replicas. Above 1, adds a PodDisruptionBudget and spreads the replicas by the platform's `globalAppTopologySpreadConstraints`, or softly across zones and nodes when it is unset.",
5152
"type": "integer",
52-
"default": 1
53+
"default": 1,
54+
"minimum": 1
5355
}
5456
}
5557
},
@@ -61,7 +63,8 @@
6163
"replicas": {
6264
"description": "Number of core replicas, which issue the token every pull and push needs. Above 1, adds a PodDisruptionBudget and spreads the replicas by the platform's `globalAppTopologySpreadConstraints`, or softly across zones and nodes when it is unset.",
6365
"type": "integer",
64-
"default": 1
66+
"default": 1,
67+
"minimum": 1
6568
},
6669
"resources": {
6770
"description": "Explicit CPU and memory configuration. When omitted, the preset defined in `resourcesPreset` is applied.",
@@ -160,7 +163,8 @@
160163
"replicas": {
161164
"description": "Number of registry replicas; they share the S3 bucket and no local state. Above 1, adds a PodDisruptionBudget and spreads the replicas by the platform's `globalAppTopologySpreadConstraints`, or softly across zones and nodes when it is unset.",
162165
"type": "integer",
163-
"default": 1
166+
"default": 1,
167+
"minimum": 1
164168
},
165169
"resources": {
166170
"description": "Explicit CPU and memory configuration. When omitted, the preset defined in `resourcesPreset` is applied.",

‎packages/apps/harbor/values.yaml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,23 @@ storageClass: ""
7272

7373
## @typedef {struct} Nginx - Entry-point proxy configuration.
7474
## @field {int} [replicas] - Number of replicas of the proxy every `docker login`, pull and push goes through. Above 1, adds a PodDisruptionBudget and spreads the replicas by the platform's `globalAppTopologySpreadConstraints`, or softly across zones and nodes when it is unset.
75+
## @minimum 1
7576

7677
## @param {Nginx} nginx - Entry-point proxy configuration.
7778
nginx:
7879
replicas: 1
7980

8081
## @typedef {struct} Portal - Web portal configuration.
8182
## @field {int} [replicas] - Number of web portal replicas. Above 1, adds a PodDisruptionBudget and spreads the replicas by the platform's `globalAppTopologySpreadConstraints`, or softly across zones and nodes when it is unset.
83+
## @minimum 1
8284

8385
## @param {Portal} portal - Web portal configuration.
8486
portal:
8587
replicas: 1
8688

8789
## @typedef {struct} Core - Core API server configuration.
8890
## @field {int} [replicas] - Number of core replicas, which issue the token every pull and push needs. Above 1, adds a PodDisruptionBudget and spreads the replicas by the platform's `globalAppTopologySpreadConstraints`, or softly across zones and nodes when it is unset.
91+
## @minimum 1
8992
## @field {Resources} [resources] - Explicit CPU and memory configuration. When omitted, the preset defined in `resourcesPreset` is applied.
9093
## @field {ResourcesPreset} [resourcesPreset] - Default sizing preset used when `resources` is omitted.
9194

@@ -97,6 +100,7 @@ core:
97100

98101
## @typedef {struct} Registry - Container image registry configuration.
99102
## @field {int} [replicas] - Number of registry replicas; they share the S3 bucket and no local state. Above 1, adds a PodDisruptionBudget and spreads the replicas by the platform's `globalAppTopologySpreadConstraints`, or softly across zones and nodes when it is unset.
103+
## @minimum 1
100104
## @field {Resources} [resources] - Explicit CPU and memory configuration. When omitted, the preset defined in `resourcesPreset` is applied.
101105
## @field {ResourcesPreset} [resourcesPreset] - Default sizing preset used when `resources` is omitted.
102106

0 commit comments

Comments
 (0)