Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for persistentVolumeClaimRetentionPolicy field #3354

Merged
16 changes: 16 additions & 0 deletions .chloggen/3305-persistentVolumeClaimRetentionPolicy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
component: collector

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Add support for persistentVolumeClaimRetentionPolicy field"

# One or more tracking issues related to the change
issues: [3305]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
5 changes: 5 additions & 0 deletions apis/v1beta1/collector_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ func (c CollectorWebhook) Validate(ctx context.Context, r *OpenTelemetryCollecto
return warnings, fmt.Errorf("the OpenTelemetry Collector mode is set to %s, which does not support the attribute 'volumeClaimTemplates'", r.Spec.Mode)
}

// validate persistentVolumeClaimRetentionPolicy
if r.Spec.Mode != ModeStatefulSet && r.Spec.PersistentVolumeClaimRetentionPolicy != nil {
return warnings, fmt.Errorf("the OpenTelemetry Collector mode is set to %s, which does not support the attribute 'persistentVolumeClaimRetentionPolicy'", r.Spec.Mode)
}

// validate tolerations
if r.Spec.Mode == ModeSidecar && len(r.Spec.Tolerations) > 0 {
return warnings, fmt.Errorf("the OpenTelemetry Collector mode is set to %s, which does not support the attribute 'tolerations'", r.Spec.Mode)
Expand Down
15 changes: 15 additions & 0 deletions apis/v1beta1/collector_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,21 @@ func TestOTELColValidatingWebhook(t *testing.T) {
},
expectedErr: "does not support the attribute 'volumeClaimTemplates'",
},
{
name: "invalid mode with persistentVolumeClaimRetentionPolicy",
otelcol: v1beta1.OpenTelemetryCollector{
Spec: v1beta1.OpenTelemetryCollectorSpec{
Mode: v1beta1.ModeSidecar,
StatefulSetCommonFields: v1beta1.StatefulSetCommonFields{
PersistentVolumeClaimRetentionPolicy: &appsv1.StatefulSetPersistentVolumeClaimRetentionPolicy{
WhenDeleted: appsv1.RetainPersistentVolumeClaimRetentionPolicyType,
WhenScaled: appsv1.DeletePersistentVolumeClaimRetentionPolicyType,
},
},
},
},
expectedErr: "does not support the attribute 'persistentVolumeClaimRetentionPolicy'",
},
{
name: "invalid mode with tolerations",
otelcol: v1beta1.OpenTelemetryCollector{
Expand Down
6 changes: 6 additions & 0 deletions apis/v1beta1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package v1beta1

import (
appsv1 "k8s.io/api/apps/v1"
autoscalingv2 "k8s.io/api/autoscaling/v2"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/intstr"
Expand Down Expand Up @@ -243,4 +244,9 @@ type StatefulSetCommonFields struct {
// +optional
// +listType=atomic
VolumeClaimTemplates []v1.PersistentVolumeClaim `json:"volumeClaimTemplates,omitempty"`
// PersistentVolumeClaimRetentionPolicy describes the lifecycle of persistent volume claims
// created from volumeClaimTemplates.
// This only works with the following OpenTelemetryCollector modes: statefulset.
// +optional
PersistentVolumeClaimRetentionPolicy *appsv1.StatefulSetPersistentVolumeClaimRetentionPolicy `json:"persistentVolumeClaimRetentionPolicy,omitempty"`
}
6 changes: 6 additions & 0 deletions apis/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6963,6 +6963,13 @@ spec:
type: boolean
type: object
type: object
persistentVolumeClaimRetentionPolicy:
properties:
whenDeleted:
type: string
whenScaled:
type: string
type: object
podAnnotations:
additionalProperties:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6963,6 +6963,13 @@ spec:
type: boolean
type: object
type: object
persistentVolumeClaimRetentionPolicy:
properties:
whenDeleted:
type: string
whenScaled:
type: string
type: object
podAnnotations:
additionalProperties:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6949,6 +6949,13 @@ spec:
type: boolean
type: object
type: object
persistentVolumeClaimRetentionPolicy:
properties:
whenDeleted:
type: string
whenScaled:
type: string
type: object
podAnnotations:
additionalProperties:
type: string
Expand Down
52 changes: 52 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -31176,6 +31176,15 @@ This only works with the following OpenTelemetryCollector mode's: daemonset, sta
ObservabilitySpec defines how telemetry data gets handled.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#opentelemetrycollectorspecpersistentvolumeclaimretentionpolicy">persistentVolumeClaimRetentionPolicy</a></b></td>
<td>object</td>
<td>
PersistentVolumeClaimRetentionPolicy describes the lifecycle of persistent volume claims
created from volumeClaimTemplates.
This only works with the following OpenTelemetryCollector modes: statefulset.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>podAnnotations</b></td>
<td>map[string]string</td>
Expand Down Expand Up @@ -40936,6 +40945,49 @@ The operator.observability.prometheus feature gate must be enabled to use this f
</table>


### OpenTelemetryCollector.spec.persistentVolumeClaimRetentionPolicy
<sup><sup>[↩ Parent](#opentelemetrycollectorspec-1)</sup></sup>



PersistentVolumeClaimRetentionPolicy describes the lifecycle of persistent volume claims
created from volumeClaimTemplates.
This only works with the following OpenTelemetryCollector modes: statefulset.

<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
<th>Required</th>
</tr>
</thead>
<tbody><tr>
<td><b>whenDeleted</b></td>
<td>string</td>
<td>
WhenDeleted specifies what happens to PVCs created from StatefulSet
VolumeClaimTemplates when the StatefulSet is deleted. The default policy
of `Retain` causes PVCs to not be affected by StatefulSet deletion. The
`Delete` policy causes those PVCs to be deleted.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>whenScaled</b></td>
<td>string</td>
<td>
WhenScaled specifies what happens to PVCs created from StatefulSet
VolumeClaimTemplates when the StatefulSet is scaled down. The default
policy of `Retain` causes PVCs to not be affected by a scaledown. The
`Delete` policy causes the associated PVCs for any excess pods above
the replica count to be deleted.<br/>
</td>
<td>false</td>
</tr></tbody>
</table>


### OpenTelemetryCollector.spec.podDisruptionBudget
<sup><sup>[↩ Parent](#opentelemetrycollectorspec-1)</sup></sup>

Expand Down
7 changes: 4 additions & 3 deletions internal/manifests/collector/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ func StatefulSet(params manifests.Params) (*appsv1.StatefulSet, error) {
TopologySpreadConstraints: params.OtelCol.Spec.TopologySpreadConstraints,
},
},
Replicas: params.OtelCol.Spec.Replicas,
PodManagementPolicy: "Parallel",
VolumeClaimTemplates: VolumeClaimTemplates(params.OtelCol),
Replicas: params.OtelCol.Spec.Replicas,
PodManagementPolicy: "Parallel",
VolumeClaimTemplates: VolumeClaimTemplates(params.OtelCol),
PersistentVolumeClaimRetentionPolicy: params.OtelCol.Spec.PersistentVolumeClaimRetentionPolicy,
},
}, nil
}
39 changes: 39 additions & 0 deletions internal/manifests/collector/statefulset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,45 @@ func TestStatefulSetVolumeClaimTemplates(t *testing.T) {
assert.Equal(t, resource.MustParse("1Gi"), ss.Spec.VolumeClaimTemplates[0].Spec.Resources.Requests["storage"])
}

func TestStatefulSetPeristentVolumeRetentionPolicy(t *testing.T) {
// prepare
otelcol := v1beta1.OpenTelemetryCollector{
ObjectMeta: metav1.ObjectMeta{
Name: "my-instance",
},
Spec: v1beta1.OpenTelemetryCollectorSpec{
Mode: "statefulset",
StatefulSetCommonFields: v1beta1.StatefulSetCommonFields{
PersistentVolumeClaimRetentionPolicy: &appsv1.StatefulSetPersistentVolumeClaimRetentionPolicy{
WhenDeleted: appsv1.RetainPersistentVolumeClaimRetentionPolicyType,
WhenScaled: appsv1.DeletePersistentVolumeClaimRetentionPolicyType,
},
},
},
}
cfg := config.New()

params := manifests.Params{
OtelCol: otelcol,
Config: cfg,
Log: logger,
}

// test
ss, err := StatefulSet(params)
require.NoError(t, err)

// assert PersistentVolumeClaimRetentionPolicy added
assert.NotNil(t, ss.Spec.PersistentVolumeClaimRetentionPolicy)

// assert correct WhenDeleted value
assert.Equal(t, ss.Spec.PersistentVolumeClaimRetentionPolicy.WhenDeleted, appsv1.RetainPersistentVolumeClaimRetentionPolicyType)

// assert correct WhenScaled value
assert.Equal(t, ss.Spec.PersistentVolumeClaimRetentionPolicy.WhenScaled, appsv1.DeletePersistentVolumeClaimRetentionPolicyType)

}

func TestStatefulSetPodAnnotations(t *testing.T) {
// prepare
testPodAnnotationValues := map[string]string{"annotation-key": "annotation-value"}
Expand Down
Loading