mirror of
https://github.com/cozystack/cozystack.git
synced 2026-12-05 14:42:05 +09:00
fix(harbor): keep the trivy volume class of the live StatefulSet (#5541)
## What this PR does
A Harbor with trivy enabled and no `storageClass` cannot be changed
after install: every upgrade of `harbor-<name>-system` is rejected on
the trivy StatefulSet, so the release stays not Ready and no later chart
change reaches it. The chart read the class for the trivy
`volumeClaimTemplate` from the PVC, which the default-StorageClass
admission stamps, instead of from the StatefulSet template, which it
never touches. The commit reads the class from the live StatefulSet
template.
The failure was reproduced on a cluster running v1.7.3 by patching a
Harbor created with `spec: {}`. The new helm-unittest suite mocks the
live StatefulSet and its defaulted PVC; all three cases fail on main and
pass here, and the 77 tests of the chart pass.
Closes #5540
### Screenshots
Not a UI change.
### Downstream repositories
- [x] No downstream repository is affected by this change
- [ ] [cozystack/website](https://github.com/cozystack/website) -
follow-up:
- [ ]
[cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack)
- follow-up:
- [ ]
[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:
### Release note
```release-note
fix(harbor): a Harbor with trivy enabled and no storageClass can be changed after install again; the chart keeps the volume class of the live trivy StatefulSet instead of copying the class the PVC got from the default StorageClass.
```
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
## Summary by CodeRabbit
* **Bug Fixes**
* Trivy storage-class handling now reflects the storage class configured
on its StatefulSet volume template. Existing fallback behavior is
unchanged.
* **Tests**
* Added coverage for Trivy storage-class behavior when the StatefulSet
template has no storage class, when a storage class is configured, and
when the chart’s `storageClass` setting is present.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
2 files changed
+122
-10
No files matched your search
@@ -61,10 +61,12 @@
|
||||
storageClassName on a PVC is immutable, and a StatefulSet's volumeClaimTemplate
|
||||
cannot be patched at all. The upstream chart renders both the jobservice PVC and
|
||||
the trivy VCT without a storageClassName unless one is passed, so on first install
|
||||
the default-StorageClass admission stamps the cluster default onto the live object.
|
||||
To avoid an immutable-field rejection on upgrade we keep the rendered value equal
|
||||
to the live one: preserve an existing object's storageClassName, and only fall back
|
||||
to the configured storageClass for a fresh install. See issue #2368.
|
||||
the default-StorageClass admission stamps the cluster default onto the jobservice
|
||||
PVC, while the StatefulSet keeps its template as rendered and only the PVCs it
|
||||
creates get the default. To avoid an immutable-field rejection on upgrade we keep
|
||||
the rendered value equal to the live one: preserve the storageClassName of the
|
||||
jobservice PVC and of the trivy StatefulSet's template, and only fall back to the
|
||||
configured storageClass for a fresh install. See issue #2368.
|
||||
|
||||
A live object pinned to an explicit "" (no dynamic provisioning) must round-trip
|
||||
too: upstream maps the "-" sentinel back to storageClassName: "", so forward "-"
|
||||
@@ -83,13 +85,15 @@
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
{{- /* The trivy StatefulSet's VCT is named "data", so its PVCs are
|
||||
data-<release>-trivy-0..N; the class is identical across ordinals, so the
|
||||
first ordinal is representative. */}}
|
||||
{{- $trivyPvc := lookup "v1" "PersistentVolumeClaim" .Release.Namespace (printf "data-%s-trivy-0" .Release.Name) }}
|
||||
{{- $trivySts := lookup "apps/v1" "StatefulSet" .Release.Namespace (printf "%s-trivy" .Release.Name) }}
|
||||
{{- $trivyStorageClass := .Values.storageClass }}
|
||||
{{- if $trivyPvc }}
|
||||
{{- $trivySpec := $trivyPvc.spec | default dict }}
|
||||
{{- if $trivySts }}
|
||||
{{- $trivySpec := dict }}
|
||||
{{- range ($trivySts.spec.volumeClaimTemplates | default list) }}
|
||||
{{- if eq .metadata.name "data" }}
|
||||
{{- $trivySpec = .spec | default dict }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- if hasKey $trivySpec "storageClassName" }}
|
||||
{{- $trivyStorageClass = $trivySpec.storageClassName | default "-" }}
|
||||
{{- else }}
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
suite: trivy storageClass follows the live StatefulSet template
|
||||
|
||||
release:
|
||||
name: harbor
|
||||
namespace: tenant-test
|
||||
|
||||
# The default-StorageClass admission stamps the class onto the PVCs the trivy
|
||||
# StatefulSet creates, not onto the StatefulSet's volumeClaimTemplate. Reading
|
||||
# the PVC rendered that stamped class into an immutable template that was
|
||||
# created without one, and the next upgrade of the release failed with
|
||||
# "updates to statefulset spec for fields other than ... are forbidden".
|
||||
set:
|
||||
_namespace:
|
||||
host: example.org
|
||||
ingress: nginx
|
||||
gateway: ""
|
||||
seaweedfs: seaweedfs
|
||||
_cluster:
|
||||
solver: http01
|
||||
scheme: &scheme
|
||||
"apps/v1/StatefulSet":
|
||||
gvr:
|
||||
group: apps
|
||||
version: v1
|
||||
resource: statefulsets
|
||||
namespaced: true
|
||||
"v1/PersistentVolumeClaim":
|
||||
gvr:
|
||||
group: ""
|
||||
version: v1
|
||||
resource: persistentvolumeclaims
|
||||
namespaced: true
|
||||
stsWithoutClass: &stsWithoutClass
|
||||
apiVersion: apps/v1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: harbor-trivy
|
||||
namespace: tenant-test
|
||||
spec:
|
||||
volumeClaimTemplates:
|
||||
- metadata:
|
||||
name: data
|
||||
spec:
|
||||
accessModes: [ReadWriteOnce]
|
||||
stsWithClass: &stsWithClass
|
||||
apiVersion: apps/v1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: harbor-trivy
|
||||
namespace: tenant-test
|
||||
spec:
|
||||
volumeClaimTemplates:
|
||||
- metadata:
|
||||
name: data
|
||||
spec:
|
||||
accessModes: [ReadWriteOnce]
|
||||
storageClassName: replicated
|
||||
defaultedPvc: &defaultedPvc
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: data-harbor-trivy-0
|
||||
namespace: tenant-test
|
||||
spec:
|
||||
accessModes: [ReadWriteOnce]
|
||||
storageClassName: local
|
||||
|
||||
tests:
|
||||
- it: keeps the class omitted when the live template has none, whatever the PVC got
|
||||
template: templates/harbor.yaml
|
||||
documentSelector:
|
||||
path: kind
|
||||
value: HelmRelease
|
||||
kubernetesProvider:
|
||||
scheme: *scheme
|
||||
objects: [*stsWithoutClass, *defaultedPvc]
|
||||
asserts:
|
||||
- notExists:
|
||||
path: spec.values.harbor.persistence.persistentVolumeClaim.trivy.storageClass
|
||||
|
||||
- it: keeps the class omitted even when storageClass is set later
|
||||
template: templates/harbor.yaml
|
||||
documentSelector:
|
||||
path: kind
|
||||
value: HelmRelease
|
||||
set:
|
||||
storageClass: local-3rep
|
||||
kubernetesProvider:
|
||||
scheme: *scheme
|
||||
objects: [*stsWithoutClass, *defaultedPvc]
|
||||
asserts:
|
||||
- notExists:
|
||||
path: spec.values.harbor.persistence.persistentVolumeClaim.trivy.storageClass
|
||||
|
||||
- it: keeps the class the live template carries
|
||||
template: templates/harbor.yaml
|
||||
documentSelector:
|
||||
path: kind
|
||||
value: HelmRelease
|
||||
set:
|
||||
storageClass: local-3rep
|
||||
kubernetesProvider:
|
||||
scheme: *scheme
|
||||
objects: [*stsWithClass, *defaultedPvc]
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.values.harbor.persistence.persistentVolumeClaim.trivy.storageClass
|
||||
value: replicated
|
||||
Reference in new issue
Block a user