Skip to content

Commit

Permalink
volumeClaimTemplates mutation through range
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhaja committed Oct 16, 2024
1 parent c04bfd9 commit 1d1ebb1
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 1 deletion.
10 changes: 9 additions & 1 deletion internal/manifests/mutate.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,12 @@ func mutateStatefulSet(existing, desired *appsv1.StatefulSet) error {
existing.Spec.RevisionHistoryLimit = desired.Spec.RevisionHistoryLimit
existing.Spec.ServiceName = desired.Spec.ServiceName
existing.Spec.UpdateStrategy = desired.Spec.UpdateStrategy
existing.Spec.VolumeClaimTemplates = desired.Spec.VolumeClaimTemplates

for i := range existing.Spec.VolumeClaimTemplates {
existing.Spec.VolumeClaimTemplates[i].TypeMeta = desired.Spec.VolumeClaimTemplates[i].TypeMeta
existing.Spec.VolumeClaimTemplates[i].ObjectMeta = desired.Spec.VolumeClaimTemplates[i].ObjectMeta
existing.Spec.VolumeClaimTemplates[i].Spec = desired.Spec.VolumeClaimTemplates[i].Spec
}

if err := mutatePodTemplate(&existing.Spec.Template, &desired.Spec.Template); err != nil {
return err
Expand Down Expand Up @@ -409,6 +414,9 @@ func hasVolumeClaimsTemplatesChanged(existing, desired *appsv1.StatefulSet) bool
if !apiequality.Semantic.DeepEqual(desired.Spec.VolumeClaimTemplates[i].Annotations, existing.Spec.VolumeClaimTemplates[i].Annotations) {
return true
}
if !apiequality.Semantic.DeepEqual(desired.Spec.VolumeClaimTemplates[i].Labels, existing.Spec.VolumeClaimTemplates[i].Labels) {
return true
}
if !apiequality.Semantic.DeepEqual(desired.Spec.VolumeClaimTemplates[i].Spec, existing.Spec.VolumeClaimTemplates[i].Spec) {
return true
}
Expand Down
43 changes: 43 additions & 0 deletions tests/e2e/volume-claim-label/00-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: stateful-collector
spec:
podManagementPolicy: Parallel
template:
spec:
containers:
- args:
- --config=/conf/collector.yaml
name: otc-container
volumeMounts:
- mountPath: /conf
name: otc-internal
- mountPath: /usr/share/testvolume
name: testvolume
volumes:
- configMap:
items:
- key: collector.yaml
path: collector.yaml
name: stateful-collector-4b08af22
name: otc-internal
- emptyDir: {}
name: testvolume
volumeClaimTemplates:
- apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: testvolume
labels:
test: "true"
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
volumeMode: Filesystem
status:
replicas: 3
readyReplicas: 3
35 changes: 35 additions & 0 deletions tests/e2e/volume-claim-label/00-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: opentelemetry.io/v1alpha1
kind: OpenTelemetryCollector
metadata:
name: stateful
spec:
mode: statefulset
replicas: 3
volumes:
- name: testvolume
volumeMounts:
- name: testvolume
mountPath: /usr/share/testvolume
volumeClaimTemplates:
- metadata:
name: testvolume
labels:
test: "true"
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
config: |
receivers:
jaeger:
protocols:
grpc:
processors:
exporters:
debug:
service:
pipelines:
traces:
receivers: [jaeger]
exporters: [debug]
43 changes: 43 additions & 0 deletions tests/e2e/volume-claim-label/01-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: stateful-collector
spec:
podManagementPolicy: Parallel
template:
spec:
containers:
- args:
- --config=/conf/collector.yaml
name: otc-container
volumeMounts:
- mountPath: /conf
name: otc-internal
- mountPath: /usr/share/testvolume
name: testvolume
volumes:
- configMap:
items:
- key: collector.yaml
path: collector.yaml
name: stateful-collector-4b08af22
name: otc-internal
- emptyDir: {}
name: testvolume
volumeClaimTemplates:
- apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: testvolume
labels:
test: "updated"
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
volumeMode: Filesystem
status:
replicas: 3
readyReplicas: 3
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: opentelemetry.io/v1alpha1
kind: OpenTelemetryCollector
metadata:
name: stateful
spec:
mode: statefulset
replicas: 3
volumes:
- name: testvolume
volumeMounts:
- name: testvolume
mountPath: /usr/share/testvolume
volumeClaimTemplates:
- metadata:
name: testvolume
labels:
test: "updated"
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
config: |
receivers:
jaeger:
protocols:
grpc:
processors:
exporters:
debug:
service:
pipelines:
traces:
receivers: [jaeger]
exporters: [debug]
20 changes: 20 additions & 0 deletions tests/e2e/volume-claim-label/chainsaw-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
creationTimestamp: null
name: persistent-volume-claim-label
spec:
steps:
- name: step-00
try:
- apply:
file: 00-install.yaml
- assert:
file: 00-assert.yaml
- name: step-01
try:
- apply:
file: 01-update-volume-claim-template-labels.yaml
- assert:
file: 01-assert.yaml

0 comments on commit 1d1ebb1

Please sign in to comment.