diff --git a/Documentation/api.md b/Documentation/api.md index 9ad2d128b..1d3cf63af 100644 --- a/Documentation/api.md +++ b/Documentation/api.md @@ -1817,6 +1817,23 @@ container, that are generated as a result of StorageSpec objects.</p> </tr> <tr> <td> +<code>persistentVolumeClaimRetentionPolicy</code><br/> +<em> +<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#statefulsetpersistentvolumeclaimretentionpolicy-v1-apps"> +Kubernetes apps/v1.StatefulSetPersistentVolumeClaimRetentionPolicy +</a> +</em> +</td> +<td> +<em>(Optional)</em> +<p>The field controls if and how PVCs are deleted during the lifecycle of a StatefulSet. +The default behavior is all PVCs are retained. +This is an alpha field from kubernetes 1.23 until 1.26 and a beta field from 1.26. +It requires enabling the StatefulSetAutoDeletePVC feature gate.</p> +</td> +</tr> +<tr> +<td> <code>web</code><br/> <em> <a href="#monitoring.coreos.com/v1.PrometheusWebSpec"> @@ -6062,6 +6079,23 @@ container, that are generated as a result of StorageSpec objects.</p> </tr> <tr> <td> +<code>persistentVolumeClaimRetentionPolicy</code><br/> +<em> +<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#statefulsetpersistentvolumeclaimretentionpolicy-v1-apps"> +Kubernetes apps/v1.StatefulSetPersistentVolumeClaimRetentionPolicy +</a> +</em> +</td> +<td> +<em>(Optional)</em> +<p>The field controls if and how PVCs are deleted during the lifecycle of a StatefulSet. +The default behavior is all PVCs are retained. +This is an alpha field from kubernetes 1.23 until 1.26 and a beta field from 1.26. +It requires enabling the StatefulSetAutoDeletePVC feature gate.</p> +</td> +</tr> +<tr> +<td> <code>web</code><br/> <em> <a href="#monitoring.coreos.com/v1.PrometheusWebSpec"> @@ -9831,6 +9865,23 @@ container, that are generated as a result of StorageSpec objects.</p> </tr> <tr> <td> +<code>persistentVolumeClaimRetentionPolicy</code><br/> +<em> +<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#statefulsetpersistentvolumeclaimretentionpolicy-v1-apps"> +Kubernetes apps/v1.StatefulSetPersistentVolumeClaimRetentionPolicy +</a> +</em> +</td> +<td> +<em>(Optional)</em> +<p>The field controls if and how PVCs are deleted during the lifecycle of a StatefulSet. +The default behavior is all PVCs are retained. +This is an alpha field from kubernetes 1.23 until 1.26 and a beta field from 1.26. +It requires enabling the StatefulSetAutoDeletePVC feature gate.</p> +</td> +</tr> +<tr> +<td> <code>web</code><br/> <em> <a href="#monitoring.coreos.com/v1.PrometheusWebSpec"> @@ -15154,6 +15205,23 @@ container, that are generated as a result of StorageSpec objects.</p> </tr> <tr> <td> +<code>persistentVolumeClaimRetentionPolicy</code><br/> +<em> +<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#statefulsetpersistentvolumeclaimretentionpolicy-v1-apps"> +Kubernetes apps/v1.StatefulSetPersistentVolumeClaimRetentionPolicy +</a> +</em> +</td> +<td> +<em>(Optional)</em> +<p>The field controls if and how PVCs are deleted during the lifecycle of a StatefulSet. +The default behavior is all PVCs are retained. +This is an alpha field from kubernetes 1.23 until 1.26 and a beta field from 1.26. +It requires enabling the StatefulSetAutoDeletePVC feature gate.</p> +</td> +</tr> +<tr> +<td> <code>web</code><br/> <em> <a href="#monitoring.coreos.com/v1.PrometheusWebSpec"> @@ -19055,6 +19123,23 @@ container, that are generated as a result of StorageSpec objects.</p> </tr> <tr> <td> +<code>persistentVolumeClaimRetentionPolicy</code><br/> +<em> +<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#statefulsetpersistentvolumeclaimretentionpolicy-v1-apps"> +Kubernetes apps/v1.StatefulSetPersistentVolumeClaimRetentionPolicy +</a> +</em> +</td> +<td> +<em>(Optional)</em> +<p>The field controls if and how PVCs are deleted during the lifecycle of a StatefulSet. +The default behavior is all PVCs are retained. +This is an alpha field from kubernetes 1.23 until 1.26 and a beta field from 1.26. +It requires enabling the StatefulSetAutoDeletePVC feature gate.</p> +</td> +</tr> +<tr> +<td> <code>web</code><br/> <em> <a href="#monitoring.coreos.com/v1.PrometheusWebSpec"> diff --git a/bundle.yaml b/bundle.yaml index c5038807e..d88e96705 100644 --- a/bundle.yaml +++ b/bundle.yaml @@ -18599,6 +18599,28 @@ spec: description: When a Prometheus deployment is paused, no actions except for deletion will be performed on the underlying objects. type: boolean + persistentVolumeClaimRetentionPolicy: + description: The field controls if and how PVCs are deleted during + the lifecycle of a StatefulSet. The default behavior is all PVCs + are retained. This is an alpha field from kubernetes 1.23 until + 1.26 and a beta field from 1.26. It requires enabling the StatefulSetAutoDeletePVC + feature gate. + properties: + whenDeleted: + description: 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. + type: string + whenScaled: + description: 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. + type: string + type: object podMetadata: description: "PodMetadata configures labels and annotations which are propagated to the Prometheus pods. \n The following items are @@ -27472,6 +27494,28 @@ spec: description: When a Prometheus deployment is paused, no actions except for deletion will be performed on the underlying objects. type: boolean + persistentVolumeClaimRetentionPolicy: + description: The field controls if and how PVCs are deleted during + the lifecycle of a StatefulSet. The default behavior is all PVCs + are retained. This is an alpha field from kubernetes 1.23 until + 1.26 and a beta field from 1.26. It requires enabling the StatefulSetAutoDeletePVC + feature gate. + properties: + whenDeleted: + description: 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. + type: string + whenScaled: + description: 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. + type: string + type: object podMetadata: description: "PodMetadata configures labels and annotations which are propagated to the Prometheus pods. \n The following items are diff --git a/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheusagents.yaml b/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheusagents.yaml index 2df522bf4..f1793da1b 100644 --- a/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheusagents.yaml +++ b/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheusagents.yaml @@ -4084,6 +4084,28 @@ spec: description: When a Prometheus deployment is paused, no actions except for deletion will be performed on the underlying objects. type: boolean + persistentVolumeClaimRetentionPolicy: + description: The field controls if and how PVCs are deleted during + the lifecycle of a StatefulSet. The default behavior is all PVCs + are retained. This is an alpha field from kubernetes 1.23 until + 1.26 and a beta field from 1.26. It requires enabling the StatefulSetAutoDeletePVC + feature gate. + properties: + whenDeleted: + description: 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. + type: string + whenScaled: + description: 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. + type: string + type: object podMetadata: description: "PodMetadata configures labels and annotations which are propagated to the Prometheus pods. \n The following items are diff --git a/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheuses.yaml b/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheuses.yaml index 35c4286c9..e2bcd1854 100644 --- a/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheuses.yaml +++ b/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheuses.yaml @@ -4515,6 +4515,28 @@ spec: description: When a Prometheus deployment is paused, no actions except for deletion will be performed on the underlying objects. type: boolean + persistentVolumeClaimRetentionPolicy: + description: The field controls if and how PVCs are deleted during + the lifecycle of a StatefulSet. The default behavior is all PVCs + are retained. This is an alpha field from kubernetes 1.23 until + 1.26 and a beta field from 1.26. It requires enabling the StatefulSetAutoDeletePVC + feature gate. + properties: + whenDeleted: + description: 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. + type: string + whenScaled: + description: 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. + type: string + type: object podMetadata: description: "PodMetadata configures labels and annotations which are propagated to the Prometheus pods. \n The following items are diff --git a/example/prometheus-operator-crd/monitoring.coreos.com_prometheusagents.yaml b/example/prometheus-operator-crd/monitoring.coreos.com_prometheusagents.yaml index 7d96e4122..c8ba2e63c 100644 --- a/example/prometheus-operator-crd/monitoring.coreos.com_prometheusagents.yaml +++ b/example/prometheus-operator-crd/monitoring.coreos.com_prometheusagents.yaml @@ -4085,6 +4085,28 @@ spec: description: When a Prometheus deployment is paused, no actions except for deletion will be performed on the underlying objects. type: boolean + persistentVolumeClaimRetentionPolicy: + description: The field controls if and how PVCs are deleted during + the lifecycle of a StatefulSet. The default behavior is all PVCs + are retained. This is an alpha field from kubernetes 1.23 until + 1.26 and a beta field from 1.26. It requires enabling the StatefulSetAutoDeletePVC + feature gate. + properties: + whenDeleted: + description: 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. + type: string + whenScaled: + description: 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. + type: string + type: object podMetadata: description: "PodMetadata configures labels and annotations which are propagated to the Prometheus pods. \n The following items are diff --git a/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml b/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml index 463207209..eff7f34e8 100644 --- a/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml +++ b/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml @@ -4516,6 +4516,28 @@ spec: description: When a Prometheus deployment is paused, no actions except for deletion will be performed on the underlying objects. type: boolean + persistentVolumeClaimRetentionPolicy: + description: The field controls if and how PVCs are deleted during + the lifecycle of a StatefulSet. The default behavior is all PVCs + are retained. This is an alpha field from kubernetes 1.23 until + 1.26 and a beta field from 1.26. It requires enabling the StatefulSetAutoDeletePVC + feature gate. + properties: + whenDeleted: + description: 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. + type: string + whenScaled: + description: 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. + type: string + type: object podMetadata: description: "PodMetadata configures labels and annotations which are propagated to the Prometheus pods. \n The following items are diff --git a/jsonnet/prometheus-operator/prometheusagents-crd.json b/jsonnet/prometheus-operator/prometheusagents-crd.json index 8b4862aa0..b267be285 100644 --- a/jsonnet/prometheus-operator/prometheusagents-crd.json +++ b/jsonnet/prometheus-operator/prometheusagents-crd.json @@ -3657,6 +3657,20 @@ "description": "When a Prometheus deployment is paused, no actions except for deletion will be performed on the underlying objects.", "type": "boolean" }, + "persistentVolumeClaimRetentionPolicy": { + "description": "The field controls if and how PVCs are deleted during the lifecycle of a StatefulSet. The default behavior is all PVCs are retained. This is an alpha field from kubernetes 1.23 until 1.26 and a beta field from 1.26. It requires enabling the StatefulSetAutoDeletePVC feature gate.", + "properties": { + "whenDeleted": { + "description": "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.", + "type": "string" + }, + "whenScaled": { + "description": "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.", + "type": "string" + } + }, + "type": "object" + }, "podMetadata": { "description": "PodMetadata configures labels and annotations which are propagated to the Prometheus pods. \n The following items are reserved and cannot be overridden: * \"prometheus\" label, set to the name of the Prometheus object. * \"app.kubernetes.io/instance\" label, set to the name of the Prometheus object. * \"app.kubernetes.io/managed-by\" label, set to \"prometheus-operator\". * \"app.kubernetes.io/name\" label, set to \"prometheus\". * \"app.kubernetes.io/version\" label, set to the Prometheus version. * \"operator.prometheus.io/name\" label, set to the name of the Prometheus object. * \"operator.prometheus.io/shard\" label, set to the shard number of the Prometheus object. * \"kubectl.kubernetes.io/default-container\" annotation, set to \"prometheus\".", "properties": { diff --git a/jsonnet/prometheus-operator/prometheuses-crd.json b/jsonnet/prometheus-operator/prometheuses-crd.json index a497b495f..563443fa2 100644 --- a/jsonnet/prometheus-operator/prometheuses-crd.json +++ b/jsonnet/prometheus-operator/prometheuses-crd.json @@ -4095,6 +4095,20 @@ "description": "When a Prometheus deployment is paused, no actions except for deletion will be performed on the underlying objects.", "type": "boolean" }, + "persistentVolumeClaimRetentionPolicy": { + "description": "The field controls if and how PVCs are deleted during the lifecycle of a StatefulSet. The default behavior is all PVCs are retained. This is an alpha field from kubernetes 1.23 until 1.26 and a beta field from 1.26. It requires enabling the StatefulSetAutoDeletePVC feature gate.", + "properties": { + "whenDeleted": { + "description": "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.", + "type": "string" + }, + "whenScaled": { + "description": "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.", + "type": "string" + } + }, + "type": "object" + }, "podMetadata": { "description": "PodMetadata configures labels and annotations which are propagated to the Prometheus pods. \n The following items are reserved and cannot be overridden: * \"prometheus\" label, set to the name of the Prometheus object. * \"app.kubernetes.io/instance\" label, set to the name of the Prometheus object. * \"app.kubernetes.io/managed-by\" label, set to \"prometheus-operator\". * \"app.kubernetes.io/name\" label, set to \"prometheus\". * \"app.kubernetes.io/version\" label, set to the Prometheus version. * \"operator.prometheus.io/name\" label, set to the name of the Prometheus object. * \"operator.prometheus.io/shard\" label, set to the shard number of the Prometheus object. * \"kubectl.kubernetes.io/default-container\" annotation, set to \"prometheus\".", "properties": { diff --git a/pkg/apis/monitoring/v1/prometheus_types.go b/pkg/apis/monitoring/v1/prometheus_types.go index fff9bf06d..3b4ab4b86 100644 --- a/pkg/apis/monitoring/v1/prometheus_types.go +++ b/pkg/apis/monitoring/v1/prometheus_types.go @@ -17,6 +17,7 @@ package v1 import ( "strings" + appsv1 "k8s.io/api/apps/v1" v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -281,6 +282,14 @@ type CommonPrometheusFields struct { // container, that are generated as a result of StorageSpec objects. VolumeMounts []v1.VolumeMount `json:"volumeMounts,omitempty"` + // The field controls if and how PVCs are deleted during the lifecycle of a StatefulSet. + // The default behavior is all PVCs are retained. + // This is an alpha field from kubernetes 1.23 until 1.26 and a beta field from 1.26. + // It requires enabling the StatefulSetAutoDeletePVC feature gate. + // + // +optional + PersistentVolumeClaimRetentionPolicy *appsv1.StatefulSetPersistentVolumeClaimRetentionPolicy `json:"persistentVolumeClaimRetentionPolicy,omitempty"` + // Defines the configuration of the Prometheus web server. Web *PrometheusWebSpec `json:"web,omitempty"` diff --git a/pkg/apis/monitoring/v1/zz_generated.deepcopy.go b/pkg/apis/monitoring/v1/zz_generated.deepcopy.go index 101879d8e..f6cf001e4 100644 --- a/pkg/apis/monitoring/v1/zz_generated.deepcopy.go +++ b/pkg/apis/monitoring/v1/zz_generated.deepcopy.go @@ -20,6 +20,7 @@ package v1 import ( + appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" @@ -677,6 +678,11 @@ func (in *CommonPrometheusFields) DeepCopyInto(out *CommonPrometheusFields) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.PersistentVolumeClaimRetentionPolicy != nil { + in, out := &in.PersistentVolumeClaimRetentionPolicy, &out.PersistentVolumeClaimRetentionPolicy + *out = new(appsv1.StatefulSetPersistentVolumeClaimRetentionPolicy) + **out = **in + } if in.Web != nil { in, out := &in.Web, &out.Web *out = new(PrometheusWebSpec) diff --git a/pkg/client/applyconfiguration/monitoring/v1/commonprometheusfields.go b/pkg/client/applyconfiguration/monitoring/v1/commonprometheusfields.go index 742cc1f0e..53dd7af66 100644 --- a/pkg/client/applyconfiguration/monitoring/v1/commonprometheusfields.go +++ b/pkg/client/applyconfiguration/monitoring/v1/commonprometheusfields.go @@ -18,6 +18,7 @@ package v1 import ( monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" + appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -25,81 +26,82 @@ import ( // CommonPrometheusFieldsApplyConfiguration represents an declarative configuration of the CommonPrometheusFields type for use // with apply. type CommonPrometheusFieldsApplyConfiguration struct { - PodMetadata *EmbeddedObjectMetadataApplyConfiguration `json:"podMetadata,omitempty"` - ServiceMonitorSelector *metav1.LabelSelector `json:"serviceMonitorSelector,omitempty"` - ServiceMonitorNamespaceSelector *metav1.LabelSelector `json:"serviceMonitorNamespaceSelector,omitempty"` - PodMonitorSelector *metav1.LabelSelector `json:"podMonitorSelector,omitempty"` - PodMonitorNamespaceSelector *metav1.LabelSelector `json:"podMonitorNamespaceSelector,omitempty"` - ProbeSelector *metav1.LabelSelector `json:"probeSelector,omitempty"` - ProbeNamespaceSelector *metav1.LabelSelector `json:"probeNamespaceSelector,omitempty"` - ScrapeConfigSelector *metav1.LabelSelector `json:"scrapeConfigSelector,omitempty"` - ScrapeConfigNamespaceSelector *metav1.LabelSelector `json:"scrapeConfigNamespaceSelector,omitempty"` - Version *string `json:"version,omitempty"` - Paused *bool `json:"paused,omitempty"` - Image *string `json:"image,omitempty"` - ImagePullPolicy *corev1.PullPolicy `json:"imagePullPolicy,omitempty"` - ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"` - Replicas *int32 `json:"replicas,omitempty"` - Shards *int32 `json:"shards,omitempty"` - ReplicaExternalLabelName *string `json:"replicaExternalLabelName,omitempty"` - PrometheusExternalLabelName *string `json:"prometheusExternalLabelName,omitempty"` - LogLevel *string `json:"logLevel,omitempty"` - LogFormat *string `json:"logFormat,omitempty"` - ScrapeInterval *monitoringv1.Duration `json:"scrapeInterval,omitempty"` - ScrapeTimeout *monitoringv1.Duration `json:"scrapeTimeout,omitempty"` - ExternalLabels map[string]string `json:"externalLabels,omitempty"` - EnableRemoteWriteReceiver *bool `json:"enableRemoteWriteReceiver,omitempty"` - EnableFeatures []string `json:"enableFeatures,omitempty"` - ExternalURL *string `json:"externalUrl,omitempty"` - RoutePrefix *string `json:"routePrefix,omitempty"` - Storage *StorageSpecApplyConfiguration `json:"storage,omitempty"` - Volumes []corev1.Volume `json:"volumes,omitempty"` - VolumeMounts []corev1.VolumeMount `json:"volumeMounts,omitempty"` - Web *PrometheusWebSpecApplyConfiguration `json:"web,omitempty"` - Resources *corev1.ResourceRequirements `json:"resources,omitempty"` - NodeSelector map[string]string `json:"nodeSelector,omitempty"` - ServiceAccountName *string `json:"serviceAccountName,omitempty"` - Secrets []string `json:"secrets,omitempty"` - ConfigMaps []string `json:"configMaps,omitempty"` - Affinity *corev1.Affinity `json:"affinity,omitempty"` - Tolerations []corev1.Toleration `json:"tolerations,omitempty"` - TopologySpreadConstraints []corev1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"` - RemoteWrite []RemoteWriteSpecApplyConfiguration `json:"remoteWrite,omitempty"` - SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty"` - ListenLocal *bool `json:"listenLocal,omitempty"` - Containers []corev1.Container `json:"containers,omitempty"` - InitContainers []corev1.Container `json:"initContainers,omitempty"` - AdditionalScrapeConfigs *corev1.SecretKeySelector `json:"additionalScrapeConfigs,omitempty"` - APIServerConfig *APIServerConfigApplyConfiguration `json:"apiserverConfig,omitempty"` - PriorityClassName *string `json:"priorityClassName,omitempty"` - PortName *string `json:"portName,omitempty"` - ArbitraryFSAccessThroughSMs *ArbitraryFSAccessThroughSMsConfigApplyConfiguration `json:"arbitraryFSAccessThroughSMs,omitempty"` - OverrideHonorLabels *bool `json:"overrideHonorLabels,omitempty"` - OverrideHonorTimestamps *bool `json:"overrideHonorTimestamps,omitempty"` - IgnoreNamespaceSelectors *bool `json:"ignoreNamespaceSelectors,omitempty"` - EnforcedNamespaceLabel *string `json:"enforcedNamespaceLabel,omitempty"` - EnforcedSampleLimit *uint64 `json:"enforcedSampleLimit,omitempty"` - EnforcedTargetLimit *uint64 `json:"enforcedTargetLimit,omitempty"` - EnforcedLabelLimit *uint64 `json:"enforcedLabelLimit,omitempty"` - EnforcedLabelNameLengthLimit *uint64 `json:"enforcedLabelNameLengthLimit,omitempty"` - EnforcedLabelValueLengthLimit *uint64 `json:"enforcedLabelValueLengthLimit,omitempty"` - EnforcedKeepDroppedTargets *uint64 `json:"enforcedKeepDroppedTargets,omitempty"` - EnforcedBodySizeLimit *monitoringv1.ByteSize `json:"enforcedBodySizeLimit,omitempty"` - MinReadySeconds *uint32 `json:"minReadySeconds,omitempty"` - HostAliases []HostAliasApplyConfiguration `json:"hostAliases,omitempty"` - AdditionalArgs []ArgumentApplyConfiguration `json:"additionalArgs,omitempty"` - WALCompression *bool `json:"walCompression,omitempty"` - ExcludedFromEnforcement []ObjectReferenceApplyConfiguration `json:"excludedFromEnforcement,omitempty"` - HostNetwork *bool `json:"hostNetwork,omitempty"` - PodTargetLabels []string `json:"podTargetLabels,omitempty"` - TracingConfig *PrometheusTracingConfigApplyConfiguration `json:"tracingConfig,omitempty"` - BodySizeLimit *monitoringv1.ByteSize `json:"bodySizeLimit,omitempty"` - SampleLimit *uint64 `json:"sampleLimit,omitempty"` - TargetLimit *uint64 `json:"targetLimit,omitempty"` - LabelLimit *uint64 `json:"labelLimit,omitempty"` - LabelNameLengthLimit *uint64 `json:"labelNameLengthLimit,omitempty"` - LabelValueLengthLimit *uint64 `json:"labelValueLengthLimit,omitempty"` - KeepDroppedTargets *uint64 `json:"keepDroppedTargets,omitempty"` + PodMetadata *EmbeddedObjectMetadataApplyConfiguration `json:"podMetadata,omitempty"` + ServiceMonitorSelector *metav1.LabelSelector `json:"serviceMonitorSelector,omitempty"` + ServiceMonitorNamespaceSelector *metav1.LabelSelector `json:"serviceMonitorNamespaceSelector,omitempty"` + PodMonitorSelector *metav1.LabelSelector `json:"podMonitorSelector,omitempty"` + PodMonitorNamespaceSelector *metav1.LabelSelector `json:"podMonitorNamespaceSelector,omitempty"` + ProbeSelector *metav1.LabelSelector `json:"probeSelector,omitempty"` + ProbeNamespaceSelector *metav1.LabelSelector `json:"probeNamespaceSelector,omitempty"` + ScrapeConfigSelector *metav1.LabelSelector `json:"scrapeConfigSelector,omitempty"` + ScrapeConfigNamespaceSelector *metav1.LabelSelector `json:"scrapeConfigNamespaceSelector,omitempty"` + Version *string `json:"version,omitempty"` + Paused *bool `json:"paused,omitempty"` + Image *string `json:"image,omitempty"` + ImagePullPolicy *corev1.PullPolicy `json:"imagePullPolicy,omitempty"` + ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"` + Replicas *int32 `json:"replicas,omitempty"` + Shards *int32 `json:"shards,omitempty"` + ReplicaExternalLabelName *string `json:"replicaExternalLabelName,omitempty"` + PrometheusExternalLabelName *string `json:"prometheusExternalLabelName,omitempty"` + LogLevel *string `json:"logLevel,omitempty"` + LogFormat *string `json:"logFormat,omitempty"` + ScrapeInterval *monitoringv1.Duration `json:"scrapeInterval,omitempty"` + ScrapeTimeout *monitoringv1.Duration `json:"scrapeTimeout,omitempty"` + ExternalLabels map[string]string `json:"externalLabels,omitempty"` + EnableRemoteWriteReceiver *bool `json:"enableRemoteWriteReceiver,omitempty"` + EnableFeatures []string `json:"enableFeatures,omitempty"` + ExternalURL *string `json:"externalUrl,omitempty"` + RoutePrefix *string `json:"routePrefix,omitempty"` + Storage *StorageSpecApplyConfiguration `json:"storage,omitempty"` + Volumes []corev1.Volume `json:"volumes,omitempty"` + VolumeMounts []corev1.VolumeMount `json:"volumeMounts,omitempty"` + PersistentVolumeClaimRetentionPolicy *appsv1.StatefulSetPersistentVolumeClaimRetentionPolicy `json:"persistentVolumeClaimRetentionPolicy,omitempty"` + Web *PrometheusWebSpecApplyConfiguration `json:"web,omitempty"` + Resources *corev1.ResourceRequirements `json:"resources,omitempty"` + NodeSelector map[string]string `json:"nodeSelector,omitempty"` + ServiceAccountName *string `json:"serviceAccountName,omitempty"` + Secrets []string `json:"secrets,omitempty"` + ConfigMaps []string `json:"configMaps,omitempty"` + Affinity *corev1.Affinity `json:"affinity,omitempty"` + Tolerations []corev1.Toleration `json:"tolerations,omitempty"` + TopologySpreadConstraints []corev1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"` + RemoteWrite []RemoteWriteSpecApplyConfiguration `json:"remoteWrite,omitempty"` + SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty"` + ListenLocal *bool `json:"listenLocal,omitempty"` + Containers []corev1.Container `json:"containers,omitempty"` + InitContainers []corev1.Container `json:"initContainers,omitempty"` + AdditionalScrapeConfigs *corev1.SecretKeySelector `json:"additionalScrapeConfigs,omitempty"` + APIServerConfig *APIServerConfigApplyConfiguration `json:"apiserverConfig,omitempty"` + PriorityClassName *string `json:"priorityClassName,omitempty"` + PortName *string `json:"portName,omitempty"` + ArbitraryFSAccessThroughSMs *ArbitraryFSAccessThroughSMsConfigApplyConfiguration `json:"arbitraryFSAccessThroughSMs,omitempty"` + OverrideHonorLabels *bool `json:"overrideHonorLabels,omitempty"` + OverrideHonorTimestamps *bool `json:"overrideHonorTimestamps,omitempty"` + IgnoreNamespaceSelectors *bool `json:"ignoreNamespaceSelectors,omitempty"` + EnforcedNamespaceLabel *string `json:"enforcedNamespaceLabel,omitempty"` + EnforcedSampleLimit *uint64 `json:"enforcedSampleLimit,omitempty"` + EnforcedTargetLimit *uint64 `json:"enforcedTargetLimit,omitempty"` + EnforcedLabelLimit *uint64 `json:"enforcedLabelLimit,omitempty"` + EnforcedLabelNameLengthLimit *uint64 `json:"enforcedLabelNameLengthLimit,omitempty"` + EnforcedLabelValueLengthLimit *uint64 `json:"enforcedLabelValueLengthLimit,omitempty"` + EnforcedKeepDroppedTargets *uint64 `json:"enforcedKeepDroppedTargets,omitempty"` + EnforcedBodySizeLimit *monitoringv1.ByteSize `json:"enforcedBodySizeLimit,omitempty"` + MinReadySeconds *uint32 `json:"minReadySeconds,omitempty"` + HostAliases []HostAliasApplyConfiguration `json:"hostAliases,omitempty"` + AdditionalArgs []ArgumentApplyConfiguration `json:"additionalArgs,omitempty"` + WALCompression *bool `json:"walCompression,omitempty"` + ExcludedFromEnforcement []ObjectReferenceApplyConfiguration `json:"excludedFromEnforcement,omitempty"` + HostNetwork *bool `json:"hostNetwork,omitempty"` + PodTargetLabels []string `json:"podTargetLabels,omitempty"` + TracingConfig *PrometheusTracingConfigApplyConfiguration `json:"tracingConfig,omitempty"` + BodySizeLimit *monitoringv1.ByteSize `json:"bodySizeLimit,omitempty"` + SampleLimit *uint64 `json:"sampleLimit,omitempty"` + TargetLimit *uint64 `json:"targetLimit,omitempty"` + LabelLimit *uint64 `json:"labelLimit,omitempty"` + LabelNameLengthLimit *uint64 `json:"labelNameLengthLimit,omitempty"` + LabelValueLengthLimit *uint64 `json:"labelValueLengthLimit,omitempty"` + KeepDroppedTargets *uint64 `json:"keepDroppedTargets,omitempty"` } // CommonPrometheusFieldsApplyConfiguration constructs an declarative configuration of the CommonPrometheusFields type for use with @@ -362,6 +364,14 @@ func (b *CommonPrometheusFieldsApplyConfiguration) WithVolumeMounts(values ...co return b } +// WithPersistentVolumeClaimRetentionPolicy sets the PersistentVolumeClaimRetentionPolicy field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the PersistentVolumeClaimRetentionPolicy field is set to the value of the last call. +func (b *CommonPrometheusFieldsApplyConfiguration) WithPersistentVolumeClaimRetentionPolicy(value appsv1.StatefulSetPersistentVolumeClaimRetentionPolicy) *CommonPrometheusFieldsApplyConfiguration { + b.PersistentVolumeClaimRetentionPolicy = &value + return b +} + // WithWeb sets the Web field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the Web field is set to the value of the last call. diff --git a/pkg/client/applyconfiguration/monitoring/v1/prometheusspec.go b/pkg/client/applyconfiguration/monitoring/v1/prometheusspec.go index a7ad3a2c9..2d6056747 100644 --- a/pkg/client/applyconfiguration/monitoring/v1/prometheusspec.go +++ b/pkg/client/applyconfiguration/monitoring/v1/prometheusspec.go @@ -18,6 +18,7 @@ package v1 import ( monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" + appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -310,6 +311,14 @@ func (b *PrometheusSpecApplyConfiguration) WithVolumeMounts(values ...corev1.Vol return b } +// WithPersistentVolumeClaimRetentionPolicy sets the PersistentVolumeClaimRetentionPolicy field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the PersistentVolumeClaimRetentionPolicy field is set to the value of the last call. +func (b *PrometheusSpecApplyConfiguration) WithPersistentVolumeClaimRetentionPolicy(value appsv1.StatefulSetPersistentVolumeClaimRetentionPolicy) *PrometheusSpecApplyConfiguration { + b.PersistentVolumeClaimRetentionPolicy = &value + return b +} + // WithWeb sets the Web field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the Web field is set to the value of the last call. diff --git a/pkg/client/applyconfiguration/monitoring/v1alpha1/prometheusagentspec.go b/pkg/client/applyconfiguration/monitoring/v1alpha1/prometheusagentspec.go index 81740fb7e..0c755497b 100644 --- a/pkg/client/applyconfiguration/monitoring/v1alpha1/prometheusagentspec.go +++ b/pkg/client/applyconfiguration/monitoring/v1alpha1/prometheusagentspec.go @@ -19,6 +19,7 @@ package v1alpha1 import ( monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" v1 "github.com/prometheus-operator/prometheus-operator/pkg/client/applyconfiguration/monitoring/v1" + appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -289,6 +290,14 @@ func (b *PrometheusAgentSpecApplyConfiguration) WithVolumeMounts(values ...corev return b } +// WithPersistentVolumeClaimRetentionPolicy sets the PersistentVolumeClaimRetentionPolicy field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the PersistentVolumeClaimRetentionPolicy field is set to the value of the last call. +func (b *PrometheusAgentSpecApplyConfiguration) WithPersistentVolumeClaimRetentionPolicy(value appsv1.StatefulSetPersistentVolumeClaimRetentionPolicy) *PrometheusAgentSpecApplyConfiguration { + b.PersistentVolumeClaimRetentionPolicy = &value + return b +} + // WithWeb sets the Web field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the Web field is set to the value of the last call. diff --git a/pkg/prometheus/agent/statefulset.go b/pkg/prometheus/agent/statefulset.go index 7d79eba88..8ec641567 100644 --- a/pkg/prometheus/agent/statefulset.go +++ b/pkg/prometheus/agent/statefulset.go @@ -153,6 +153,10 @@ func makeStatefulSet( statefulset.Spec.Template.Spec.Volumes = append(statefulset.Spec.Template.Spec.Volumes, cpf.Volumes...) + if cpf.PersistentVolumeClaimRetentionPolicy != nil { + statefulset.Spec.PersistentVolumeClaimRetentionPolicy = cpf.PersistentVolumeClaimRetentionPolicy + } + if cpf.HostNetwork { statefulset.Spec.Template.Spec.DNSPolicy = v1.DNSClusterFirstWithHostNet } diff --git a/pkg/prometheus/server/statefulset.go b/pkg/prometheus/server/statefulset.go index c1e6bbd61..adeb56b2e 100644 --- a/pkg/prometheus/server/statefulset.go +++ b/pkg/prometheus/server/statefulset.go @@ -216,6 +216,10 @@ func makeStatefulSet( statefulset.Spec.Template.Spec.Volumes = append(statefulset.Spec.Template.Spec.Volumes, cpf.Volumes...) + if cpf.PersistentVolumeClaimRetentionPolicy != nil { + statefulset.Spec.PersistentVolumeClaimRetentionPolicy = cpf.PersistentVolumeClaimRetentionPolicy + } + if cpf.HostNetwork { statefulset.Spec.Template.Spec.DNSPolicy = v1.DNSClusterFirstWithHostNet } diff --git a/pkg/prometheus/server/statefulset_test.go b/pkg/prometheus/server/statefulset_test.go index 897ecfbac..11a58bf6d 100644 --- a/pkg/prometheus/server/statefulset_test.go +++ b/pkg/prometheus/server/statefulset_test.go @@ -2806,3 +2806,26 @@ func TestPodHostNetworkConfig(t *testing.T) { t.Fatalf("expected DNSPolicy configuration to match due to hostNetwork but failed") } } + +func TestPersistentVolumeClaimRetentionPolicy(t *testing.T) { + sset, err := makeStatefulSetFromPrometheus(monitoringv1.Prometheus{ + ObjectMeta: metav1.ObjectMeta{}, + Spec: monitoringv1.PrometheusSpec{ + CommonPrometheusFields: monitoringv1.CommonPrometheusFields{ + PersistentVolumeClaimRetentionPolicy: &appsv1.StatefulSetPersistentVolumeClaimRetentionPolicy{ + WhenDeleted: appsv1.DeletePersistentVolumeClaimRetentionPolicyType, + WhenScaled: appsv1.DeletePersistentVolumeClaimRetentionPolicyType, + }, + }, + }, + }) + require.NoError(t, err) + + if sset.Spec.PersistentVolumeClaimRetentionPolicy.WhenDeleted != appsv1.DeletePersistentVolumeClaimRetentionPolicyType { + t.Fatalf("expected persistentVolumeClaimDeletePolicy.WhenDeleted to be %s but got %s", appsv1.DeletePersistentVolumeClaimRetentionPolicyType, sset.Spec.PersistentVolumeClaimRetentionPolicy.WhenDeleted) + } + + if sset.Spec.PersistentVolumeClaimRetentionPolicy.WhenScaled != appsv1.DeletePersistentVolumeClaimRetentionPolicyType { + t.Fatalf("expected persistentVolumeClaimDeletePolicy.WhenScaled to be %s but got %s", appsv1.DeletePersistentVolumeClaimRetentionPolicyType, sset.Spec.PersistentVolumeClaimRetentionPolicy.WhenScaled) + } +}