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:
52 changes: 27 additions & 25 deletions apis/v1alpha1/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ func tov1beta1(in OpenTelemetryCollector) (v1beta1.OpenTelemetryCollector, error
AdditionalContainers: copy.Spec.AdditionalContainers,
},
StatefulSetCommonFields: v1beta1.StatefulSetCommonFields{
VolumeClaimTemplates: copy.Spec.VolumeClaimTemplates,
VolumeClaimTemplates: copy.Spec.VolumeClaimTemplates,
swiatekm marked this conversation as resolved.
Show resolved Hide resolved
PersistentVolumeClaimRetentionPolicy: copy.Spec.PersistentVolumeClaimRetentionPolicy,
},
Autoscaler: tov1beta1Autoscaler(copy.Spec.Autoscaler, copy.Spec.MinReplicas, copy.Spec.MaxReplicas),
TargetAllocator: tov1beta1TA(copy.Spec.TargetAllocator),
Expand Down Expand Up @@ -312,30 +313,31 @@ func tov1alpha1(in v1beta1.OpenTelemetryCollector) (*OpenTelemetryCollector, err
},

Spec: OpenTelemetryCollectorSpec{
ManagementState: ManagementStateType(copy.Spec.ManagementState),
Resources: copy.Spec.Resources,
NodeSelector: copy.Spec.NodeSelector,
Args: copy.Spec.Args,
Replicas: copy.Spec.Replicas,
Autoscaler: tov1alpha1Autoscaler(copy.Spec.Autoscaler),
PodDisruptionBudget: tov1alpha1PodDisruptionBudget(copy.Spec.PodDisruptionBudget),
SecurityContext: copy.Spec.SecurityContext,
PodSecurityContext: copy.Spec.PodSecurityContext,
PodAnnotations: copy.Spec.PodAnnotations,
TargetAllocator: tov1alpha1TA(copy.Spec.TargetAllocator),
Mode: Mode(copy.Spec.Mode),
ServiceAccount: copy.Spec.ServiceAccount,
Image: copy.Spec.Image,
UpgradeStrategy: UpgradeStrategy(copy.Spec.UpgradeStrategy),
ImagePullPolicy: copy.Spec.ImagePullPolicy,
Config: configYaml,
VolumeMounts: copy.Spec.VolumeMounts,
Ports: tov1alpha1Ports(copy.Spec.Ports),
Env: copy.Spec.Env,
EnvFrom: copy.Spec.EnvFrom,
VolumeClaimTemplates: copy.Spec.VolumeClaimTemplates,
Tolerations: copy.Spec.Tolerations,
Volumes: copy.Spec.Volumes,
ManagementState: ManagementStateType(copy.Spec.ManagementState),
Resources: copy.Spec.Resources,
NodeSelector: copy.Spec.NodeSelector,
Args: copy.Spec.Args,
Replicas: copy.Spec.Replicas,
Autoscaler: tov1alpha1Autoscaler(copy.Spec.Autoscaler),
PodDisruptionBudget: tov1alpha1PodDisruptionBudget(copy.Spec.PodDisruptionBudget),
SecurityContext: copy.Spec.SecurityContext,
PodSecurityContext: copy.Spec.PodSecurityContext,
PodAnnotations: copy.Spec.PodAnnotations,
TargetAllocator: tov1alpha1TA(copy.Spec.TargetAllocator),
Mode: Mode(copy.Spec.Mode),
ServiceAccount: copy.Spec.ServiceAccount,
Image: copy.Spec.Image,
UpgradeStrategy: UpgradeStrategy(copy.Spec.UpgradeStrategy),
ImagePullPolicy: copy.Spec.ImagePullPolicy,
Config: configYaml,
VolumeMounts: copy.Spec.VolumeMounts,
Ports: tov1alpha1Ports(copy.Spec.Ports),
Env: copy.Spec.Env,
EnvFrom: copy.Spec.EnvFrom,
VolumeClaimTemplates: copy.Spec.VolumeClaimTemplates,
PersistentVolumeClaimRetentionPolicy: copy.Spec.PersistentVolumeClaimRetentionPolicy,
Tolerations: copy.Spec.Tolerations,
Volumes: copy.Spec.Volumes,
Ingress: Ingress{
Type: IngressType(copy.Spec.Ingress.Type),
RuleType: IngressRuleType(copy.Spec.Ingress.RuleType),
Expand Down
4 changes: 4 additions & 0 deletions apis/v1alpha1/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ func Test_tov1beta1AndBack(t *testing.T) {
},
},
},
PersistentVolumeClaimRetentionPolicy: &appsv1.StatefulSetPersistentVolumeClaimRetentionPolicy{
WhenDeleted: appsv1.RetainPersistentVolumeClaimRetentionPolicyType,
WhenScaled: appsv1.DeletePersistentVolumeClaimRetentionPolicyType,
},
Tolerations: []v1.Toleration{
{
Key: "11",
Expand Down
5 changes: 5 additions & 0 deletions apis/v1alpha1/opentelemetrycollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ type OpenTelemetryCollectorSpec 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 mode's: statefulset.
// +optional
PersistentVolumeClaimRetentionPolicy *appsv1.StatefulSetPersistentVolumeClaimRetentionPolicy `json:"persistentVolumeClaimRetentionPolicy,omitempty"`
// Toleration to schedule OpenTelemetry Collector pods.
// This is only relevant to daemonset, statefulset, and deployment mode
// +optional
Expand Down
6 changes: 6 additions & 0 deletions apis/v1alpha1/zz_generated.deepcopy.go

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

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 @@ -760,6 +760,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 mode's: statefulset.
davidhaja marked this conversation as resolved.
Show resolved Hide resolved
// +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 @@ -2360,6 +2360,13 @@ spec:
type: boolean
type: object
type: object
persistentVolumeClaimRetentionPolicy:
properties:
whenDeleted:
type: string
whenScaled:
type: string
type: object
podAnnotations:
additionalProperties:
type: string
Expand Down Expand Up @@ -6963,6 +6970,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 @@ -2360,6 +2360,13 @@ spec:
type: boolean
type: object
type: object
persistentVolumeClaimRetentionPolicy:
properties:
whenDeleted:
type: string
whenScaled:
type: string
type: object
podAnnotations:
additionalProperties:
type: string
Expand Down Expand Up @@ -6963,6 +6970,13 @@ spec:
type: boolean
type: object
type: object
persistentVolumeClaimRetentionPolicy:
properties:
whenDeleted:
type: string
whenScaled:
type: string
type: object
podAnnotations:
additionalProperties:
type: string
Expand Down
14 changes: 14 additions & 0 deletions config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2346,6 +2346,13 @@ spec:
type: boolean
type: object
type: object
persistentVolumeClaimRetentionPolicy:
properties:
whenDeleted:
type: string
whenScaled:
type: string
type: object
podAnnotations:
additionalProperties:
type: string
Expand Down Expand Up @@ -6949,6 +6956,13 @@ spec:
type: boolean
type: object
type: object
persistentVolumeClaimRetentionPolicy:
properties:
whenDeleted:
type: string
whenScaled:
type: string
type: object
podAnnotations:
additionalProperties:
type: string
Expand Down
Loading
Loading