← Back to Pull requests

[CLOUDPREM-889] Add BYOC and Worker defaults and runtime validation #3554

Merged
shuheiktgw merged 11 files (2368 lines) on Oct 06, 2026 11:21 UTC
View on GitHub
shuheiktgw shuheiktgw commented on Oct 05, 2026 09:08 UTC
Author

What does this PR do?

Adds the defaults and runtime validation packages for DatadogBYOCCluster and DatadogObservabilityPipelinesWorker:

internal/controller/datadogbyoccluster/defaults
internal/controller/datadogbyoccluster/validation
internal/controller/datadogobservabilitypipelinesworker/defaults
internal/controller/datadogobservabilitypipelinesworker/validation

No reconciler calls these packages yet. The upcoming controller PRs will apply defaults first and then validate the defaulted spec before image resolution, so that explicit values are also checked against the defaults they are combined with. Failures will be reported as InvalidConfiguration.

Motivation

These checks run in the reconciler instead of CEL/XValidation so that the CRDs keep working on Kubernetes versions older than 1.25. See https://github.com/DataDog/datadog-operator/pull/3501#discussion_r4080491818.

Checklist

  • PR has at least one valid label: enhancement

  • PR has a milestone or the qa/skip-qa label

  • All commits are signed
  • ---
    Jira: CLOUDPREM-889 (Epic: CLOUDPREM-431 / Initiative: LOPS-253)

    [CLOUDPREM-889]: https://datadoghq.atlassian.net/browse/CLOUDPREM-889?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

    Diff: 2368 lines (+2354 / -14) across 11 files Reviewer: levan-m Review duration: 1573m
    All Vouch review confidence checks passed
    Residual risk 0.06 = Change Risk (0.58) × (1 − Review Confidence (0.89)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.58 · 2368 lines diff across 11 files
    0.58
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.85 · 5 substantive comment(s)
    0.85
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    88%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.400
    Real PR Conversation Timeline
    40 items
    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on Oct 05, 2026 09:42 UTC
    Bot

    <!-- codex-pull-request-review-summary -->

    Codex Review Summary

    This comment shows the latest Codex review activity on this pull request.

    | Review | Status | Commit | Review trigger |
    | --- | --- | --- | --- |
    | 📝 Code Review | ✅ Completed <relative-time datetime="2026-10-06T08:41:26.154482Z">2026-10-06T08:41:26.154482Z</relative-time> | 98e9c6b | New commits |

    <details> <summary>ℹ️ About Codex in GitHub</summary>
    <br/>

    Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review

  • Mark a draft as ready

  • Comment "@codex review" or "@codex security review".
  • Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

    </details>

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on code on Oct 05, 2026 09:48 UTC
    Code Review
    internal/controller/datadogbyoccluster/validation/validation.go:1
    @@ -0,0 +1,121 @@
    +// Unless explicitly stated otherwise all files in this repository are licensed
    +// under the Apache License Version 2.0.
    +// This product includes software developed at Datadog (https://www.datadoghq.com/).
    +// Copyright 2016-present Datadog, Inc.
    +
    +// Package validation enforces BYOC cross-field rules at reconciliation time.
    +// CEL/XValidation requires Kubernetes 1.25+, but the Operator's minimum supported
    +// Kubernetes version is not being raised. OperatorHub/Red Hat installations install
    +// all CRDs in the OLM bundle; they cannot omit the BYOC CRD on older clusters.
    +// Keep these rules in the reconciler so BYOC does not impose a newer Kubernetes
    +// requirement on every Operator installation.
    +// See https://github.com/DataDog/datadog-operator/pull/3501#discussion_r4080491818.
    +package validation
    +
    +import (
    +	corev1 "k8s.io/api/core/v1"
    +	"k8s.io/apimachinery/pkg/util/validation/field"
    +
    +	datadoghqv1alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1"
    +)
    +
    +// ValidateClusterSpec checks the cross-field rules before defaults or image resolution.
    +// Required fields and single-field constraints are enforced by the CRD schema.
    +func ValidateClusterSpec(spec *datadoghqv1alpha1.DatadogBYOCClusterSpec) field.ErrorList {
    +	path := field.NewPath("spec")
    +	var errs field.ErrorList
    +	if spec.Release == nil && spec.ImageOverrides == nil {
    +		errs = append(errs, field.Required(path, "release or imageOverrides must be specified"))
    +	}
    +	if release := spec.Release; release != nil && (release.Tag == nil) == (release.Digest == nil) {
    +		errs = append(errs, field.Invalid(path.Child("release"), nil, "exactly one of tag or digest must be specified"))
    +	}
    +	if overrides := spec.ImageOverrides; overrides != nil {
    +		// Without a release, neither image can inherit a repository or version.
    +		requireComplete := spec.Release == nil
    +		errs = append(errs, validateImageOverride(overrides.BYOC, requireComplete, path.Child("imageOverrides", "byoc"))...)
    +		errs = append(errs, validateImageOverride(overrides.ObservabilityPipelinesWorker, requireComplete, path.Child("imageOverrides", "observabilityPipelinesWorker"))...)
    +	}
    +	if spec.Provider == nil || spec.Provider.AWS == nil {
    +		errs = append(errs, field.Required(path.Child("provider", "aws"), "at least one provider must be specified"))
    +	}
    +	// Validate the global setting even if every component overrides it.
    +	errs = append(errs, validatePodDisruptionBudget(spec.Global.PodDisruptionBudget, path.Child("global", "podDisruptionBudget"))...)
    +	if components := spec.Components; components != nil {
    +		componentPath := path.Child("components")
    +		errs = append(errs, ValidateStatefulComponent(components.Indexer, componentPath.Child("indexer"))...)
    +		errs = append(errs, ValidateStatefulComponent(components.Searcher, componentPath.Child("searcher"))...)
    +		for i := range components.Pipelines {
    +			errs = append(errs, ValidateStatefulComponent(&components.Pipelines[i].DatadogBYOCClusterStatefulComponentSpec, componentPath.Child("pipelines").Index(i))...)
    +		}
    +		if components.Metastore != nil {
    +			errs = append(errs, validateComponent(&components.Metastore.DatadogBYOCClusterComponentSpec, componentPath.Child("metastore"))...)
    +		}
    +		if components.ReadOnlyMetastore != nil {
    +			errs = append(errs, validateComponent(&components.ReadOnlyMetastore.DatadogBYOCClusterComponentSpec, componentPath.Child("readOnlyMetastore"))...)
    +		}
    +		errs = append(errs, validateComponent(components.ControlPlane, componentPath.Child("controlPlane"))...)
    +		errs = append(errs, validateComponent(components.Compactor, componentPath.Child("compactor"))...)
    +		errs = append(errs, validateComponent(components.Janitor, componentPath.Child("janitor"))...)
    +	}
    +	return errs
    +}
    +
    +func validateImageOverride(image *datadoghqv1alpha1.DatadogBYOCImageSpec, requireComplete bool, path *field.Path) field.ErrorList {
    +	if image == nil {
    +		if requireComplete {
    +			return field.ErrorList{field.Required(path, "image must be fully specified when release is omitted")}
    +		}
    +		return nil
    +	}
    +	var errs field.ErrorList
    +	if image.Tag != nil && image.Digest != nil {
    +		errs = append(errs, field.Forbidden(path, "tag and digest are mutually exclusive"))
    +	}
    +	if requireComplete {

    <sub><sub>!P2 Badge</sub></sub> Reject empty override digests even when a release exists

    When a valid release is combined with an override such as imageOverrides.byoc.digest: "", the CRD accepts the empty digest and this check is skipped because requireComplete is false. Image resolution then treats the non-nil digest as an explicit version override, clearing the inherited release tag and producing an image reference ending in :, so the managed workload cannot start. Validate a present digest as non-empty regardless of whether the release supplies other image fields.

    Useful? React with 👍 / 👎.

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on code on Oct 05, 2026 09:48 UTC
    Code Review
    internal/controller/datadogbyoccluster/validation/validation.go:1
    @@ -0,0 +1,121 @@
    +// Unless explicitly stated otherwise all files in this repository are licensed
    +// under the Apache License Version 2.0.
    +// This product includes software developed at Datadog (https://www.datadoghq.com/).
    +// Copyright 2016-present Datadog, Inc.
    +
    +// Package validation enforces BYOC cross-field rules at reconciliation time.
    +// CEL/XValidation requires Kubernetes 1.25+, but the Operator's minimum supported
    +// Kubernetes version is not being raised. OperatorHub/Red Hat installations install
    +// all CRDs in the OLM bundle; they cannot omit the BYOC CRD on older clusters.
    +// Keep these rules in the reconciler so BYOC does not impose a newer Kubernetes
    +// requirement on every Operator installation.
    +// See https://github.com/DataDog/datadog-operator/pull/3501#discussion_r4080491818.
    +package validation
    +
    +import (
    +	corev1 "k8s.io/api/core/v1"
    +	"k8s.io/apimachinery/pkg/util/validation/field"
    +
    +	datadoghqv1alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1"
    +)
    +
    +// ValidateClusterSpec checks the cross-field rules before defaults or image resolution.
    +// Required fields and single-field constraints are enforced by the CRD schema.
    +func ValidateClusterSpec(spec *datadoghqv1alpha1.DatadogBYOCClusterSpec) field.ErrorList {
    +	path := field.NewPath("spec")
    +	var errs field.ErrorList
    +	if spec.Release == nil && spec.ImageOverrides == nil {
    +		errs = append(errs, field.Required(path, "release or imageOverrides must be specified"))
    +	}
    +	if release := spec.Release; release != nil && (release.Tag == nil) == (release.Digest == nil) {
    +		errs = append(errs, field.Invalid(path.Child("release"), nil, "exactly one of tag or digest must be specified"))
    +	}
    +	if overrides := spec.ImageOverrides; overrides != nil {
    +		// Without a release, neither image can inherit a repository or version.
    +		requireComplete := spec.Release == nil
    +		errs = append(errs, validateImageOverride(overrides.BYOC, requireComplete, path.Child("imageOverrides", "byoc"))...)
    +		errs = append(errs, validateImageOverride(overrides.ObservabilityPipelinesWorker, requireComplete, path.Child("imageOverrides", "observabilityPipelinesWorker"))...)
    +	}
    +	if spec.Provider == nil || spec.Provider.AWS == nil {
    +		errs = append(errs, field.Required(path.Child("provider", "aws"), "at least one provider must be specified"))
    +	}
    +	// Validate the global setting even if every component overrides it.
    +	errs = append(errs, validatePodDisruptionBudget(spec.Global.PodDisruptionBudget, path.Child("global", "podDisruptionBudget"))...)
    +	if components := spec.Components; components != nil {
    +		componentPath := path.Child("components")
    +		errs = append(errs, ValidateStatefulComponent(components.Indexer, componentPath.Child("indexer"))...)
    +		errs = append(errs, ValidateStatefulComponent(components.Searcher, componentPath.Child("searcher"))...)
    +		for i := range components.Pipelines {
    +			errs = append(errs, ValidateStatefulComponent(&components.Pipelines[i].DatadogBYOCClusterStatefulComponentSpec, componentPath.Child("pipelines").Index(i))...)
    +		}
    +		if components.Metastore != nil {
    +			errs = append(errs, validateComponent(&components.Metastore.DatadogBYOCClusterComponentSpec, componentPath.Child("metastore"))...)
    +		}
    +		if components.ReadOnlyMetastore != nil {
    +			errs = append(errs, validateComponent(&components.ReadOnlyMetastore.DatadogBYOCClusterComponentSpec, componentPath.Child("readOnlyMetastore"))...)
    +		}
    +		errs = append(errs, validateComponent(components.ControlPlane, componentPath.Child("controlPlane"))...)
    +		errs = append(errs, validateComponent(components.Compactor, componentPath.Child("compactor"))...)
    +		errs = append(errs, validateComponent(components.Janitor, componentPath.Child("janitor"))...)
    +	}
    +	return errs
    +}
    +
    +func validateImageOverride(image *datadoghqv1alpha1.DatadogBYOCImageSpec, requireComplete bool, path *field.Path) field.ErrorList {
    +	if image == nil {
    +		if requireComplete {
    +			return field.ErrorList{field.Required(path, "image must be fully specified when release is omitted")}
    +		}
    +		return nil
    +	}
    +	var errs field.ErrorList
    +	if image.Tag != nil && image.Digest != nil {
    +		errs = append(errs, field.Forbidden(path, "tag and digest are mutually exclusive"))
    +	}
    +	if requireComplete {
    +		if image.Repository == nil || *image.Repository == "" {
    +			errs = append(errs, field.Required(path.Child("repository"), "repository must be non-empty when release is omitted"))
    +		}
    +		if image.Tag == nil && image.Digest == nil {
    +			errs = append(errs, field.Required(path, "tag or digest must be specified when release is omitted"))
    +		}
    +		if image.Tag != nil && *image.Tag == "" {
    +			errs = append(errs, field.Required(path.Child("tag"), "tag must be non-empty when release is omitted"))
    +		}
    +		if image.Digest != nil && *image.Digest == "" {
    +			errs = append(errs, field.Required(path.Child("digest"), "digest must be non-empty when release is omitted"))
    +		}
    +	}
    +	return errs
    +}
    +
    +// ValidateStatefulComponent is shared by BYOC components and standalone Workers.
    +func ValidateStatefulComponent(component *datadoghqv1alpha1.DatadogBYOCClusterStatefulComponentSpec, path *field.Path) field.ErrorList {
    +	if component == nil {
    +		return nil
    +	}
    +	errs := validateComponent(&component.DatadogBYOCClusterComponentSpec, path)

    <sub><sub>!P2 Badge</sub></sub> Validate explicit autoscaling bounds before defaulting

    For either a BYOC stateful component or standalone Worker with both bounds specified, this shared validator accepts configurations such as minReplicas: 5 and maxReplicas: 2 (and the generated CRDs impose no bounds). Both defaulting implementations preserve those values, so the eventual HorizontalPodAutoscaler is rejected instead of the parent resource receiving the intended configuration error. Validate that the explicit maximum is positive and not below the minimum here.

    Useful? React with 👍 / 👎.

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on Oct 05, 2026 09:48 UTC
    Reviewer

    💡 Codex Review

    Here are some automated review suggestions for this pull request.

    Reviewed commit: e59e5749b1

    <details> <summary>ℹ️ About Codex in GitHub</summary>
    <br/>

    Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review

  • Mark a draft as ready

  • Comment "@codex review".
  • If Codex has suggestions, it will comment; otherwise it will react with 👍.

    Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

    </details>

    shuheiktgw shuheiktgw commented on code on Oct 05, 2026 10:14 UTC
    Code Review
    internal/controller/datadogbyoccluster/validation/validation.go:1
    @@ -0,0 +1,121 @@
    +// Unless explicitly stated otherwise all files in this repository are licensed
    +// under the Apache License Version 2.0.
    +// This product includes software developed at Datadog (https://www.datadoghq.com/).
    +// Copyright 2016-present Datadog, Inc.
    +
    +// Package validation enforces BYOC cross-field rules at reconciliation time.
    +// CEL/XValidation requires Kubernetes 1.25+, but the Operator's minimum supported
    +// Kubernetes version is not being raised. OperatorHub/Red Hat installations install
    +// all CRDs in the OLM bundle; they cannot omit the BYOC CRD on older clusters.
    +// Keep these rules in the reconciler so BYOC does not impose a newer Kubernetes
    +// requirement on every Operator installation.
    +// See https://github.com/DataDog/datadog-operator/pull/3501#discussion_r4080491818.
    +package validation
    +
    +import (
    +	corev1 "k8s.io/api/core/v1"
    +	"k8s.io/apimachinery/pkg/util/validation/field"
    +
    +	datadoghqv1alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1"
    +)
    +
    +// ValidateClusterSpec checks the cross-field rules before defaults or image resolution.
    +// Required fields and single-field constraints are enforced by the CRD schema.
    +func ValidateClusterSpec(spec *datadoghqv1alpha1.DatadogBYOCClusterSpec) field.ErrorList {
    +	path := field.NewPath("spec")
    +	var errs field.ErrorList
    +	if spec.Release == nil && spec.ImageOverrides == nil {
    +		errs = append(errs, field.Required(path, "release or imageOverrides must be specified"))
    +	}
    +	if release := spec.Release; release != nil && (release.Tag == nil) == (release.Digest == nil) {
    +		errs = append(errs, field.Invalid(path.Child("release"), nil, "exactly one of tag or digest must be specified"))
    +	}
    +	if overrides := spec.ImageOverrides; overrides != nil {
    +		// Without a release, neither image can inherit a repository or version.
    +		requireComplete := spec.Release == nil
    +		errs = append(errs, validateImageOverride(overrides.BYOC, requireComplete, path.Child("imageOverrides", "byoc"))...)
    +		errs = append(errs, validateImageOverride(overrides.ObservabilityPipelinesWorker, requireComplete, path.Child("imageOverrides", "observabilityPipelinesWorker"))...)
    +	}
    +	if spec.Provider == nil || spec.Provider.AWS == nil {
    +		errs = append(errs, field.Required(path.Child("provider", "aws"), "at least one provider must be specified"))
    +	}
    +	// Validate the global setting even if every component overrides it.
    +	errs = append(errs, validatePodDisruptionBudget(spec.Global.PodDisruptionBudget, path.Child("global", "podDisruptionBudget"))...)
    +	if components := spec.Components; components != nil {
    +		componentPath := path.Child("components")
    +		errs = append(errs, ValidateStatefulComponent(components.Indexer, componentPath.Child("indexer"))...)
    +		errs = append(errs, ValidateStatefulComponent(components.Searcher, componentPath.Child("searcher"))...)
    +		for i := range components.Pipelines {
    +			errs = append(errs, ValidateStatefulComponent(&components.Pipelines[i].DatadogBYOCClusterStatefulComponentSpec, componentPath.Child("pipelines").Index(i))...)
    +		}
    +		if components.Metastore != nil {
    +			errs = append(errs, validateComponent(&components.Metastore.DatadogBYOCClusterComponentSpec, componentPath.Child("metastore"))...)
    +		}
    +		if components.ReadOnlyMetastore != nil {
    +			errs = append(errs, validateComponent(&components.ReadOnlyMetastore.DatadogBYOCClusterComponentSpec, componentPath.Child("readOnlyMetastore"))...)
    +		}
    +		errs = append(errs, validateComponent(components.ControlPlane, componentPath.Child("controlPlane"))...)
    +		errs = append(errs, validateComponent(components.Compactor, componentPath.Child("compactor"))...)
    +		errs = append(errs, validateComponent(components.Janitor, componentPath.Child("janitor"))...)
    +	}
    +	return errs
    +}
    +
    +func validateImageOverride(image *datadoghqv1alpha1.DatadogBYOCImageSpec, requireComplete bool, path *field.Path) field.ErrorList {
    +	if image == nil {
    +		if requireComplete {
    +			return field.ErrorList{field.Required(path, "image must be fully specified when release is omitted")}
    +		}
    +		return nil
    +	}
    +	var errs field.ErrorList
    +	if image.Tag != nil && image.Digest != nil {
    +		errs = append(errs, field.Forbidden(path, "tag and digest are mutually exclusive"))
    +	}
    +	if requireComplete {

    Fixed in f83ab35d: image digests must now match ^sha256:[a-f0-9]{64}$ in the CRD schema, so an empty override digest is rejected at admission whether or not a release is set. Release repository and tag now also require at least one character.

    shuheiktgw shuheiktgw commented on code on Oct 05, 2026 11:44 UTC
    Code Review
    internal/controller/datadogbyoccluster/validation/validation.go:1
    @@ -0,0 +1,121 @@
    +// Unless explicitly stated otherwise all files in this repository are licensed
    +// under the Apache License Version 2.0.
    +// This product includes software developed at Datadog (https://www.datadoghq.com/).
    +// Copyright 2016-present Datadog, Inc.
    +
    +// Package validation enforces BYOC cross-field rules at reconciliation time.
    +// CEL/XValidation requires Kubernetes 1.25+, but the Operator's minimum supported
    +// Kubernetes version is not being raised. OperatorHub/Red Hat installations install
    +// all CRDs in the OLM bundle; they cannot omit the BYOC CRD on older clusters.
    +// Keep these rules in the reconciler so BYOC does not impose a newer Kubernetes
    +// requirement on every Operator installation.
    +// See https://github.com/DataDog/datadog-operator/pull/3501#discussion_r4080491818.
    +package validation
    +
    +import (
    +	corev1 "k8s.io/api/core/v1"
    +	"k8s.io/apimachinery/pkg/util/validation/field"
    +
    +	datadoghqv1alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1"
    +)
    +
    +// ValidateClusterSpec checks the cross-field rules before defaults or image resolution.
    +// Required fields and single-field constraints are enforced by the CRD schema.
    +func ValidateClusterSpec(spec *datadoghqv1alpha1.DatadogBYOCClusterSpec) field.ErrorList {
    +	path := field.NewPath("spec")
    +	var errs field.ErrorList
    +	if spec.Release == nil && spec.ImageOverrides == nil {
    +		errs = append(errs, field.Required(path, "release or imageOverrides must be specified"))
    +	}
    +	if release := spec.Release; release != nil && (release.Tag == nil) == (release.Digest == nil) {
    +		errs = append(errs, field.Invalid(path.Child("release"), nil, "exactly one of tag or digest must be specified"))
    +	}
    +	if overrides := spec.ImageOverrides; overrides != nil {
    +		// Without a release, neither image can inherit a repository or version.
    +		requireComplete := spec.Release == nil
    +		errs = append(errs, validateImageOverride(overrides.BYOC, requireComplete, path.Child("imageOverrides", "byoc"))...)
    +		errs = append(errs, validateImageOverride(overrides.ObservabilityPipelinesWorker, requireComplete, path.Child("imageOverrides", "observabilityPipelinesWorker"))...)
    +	}
    +	if spec.Provider == nil || spec.Provider.AWS == nil {
    +		errs = append(errs, field.Required(path.Child("provider", "aws"), "at least one provider must be specified"))
    +	}
    +	// Validate the global setting even if every component overrides it.
    +	errs = append(errs, validatePodDisruptionBudget(spec.Global.PodDisruptionBudget, path.Child("global", "podDisruptionBudget"))...)
    +	if components := spec.Components; components != nil {
    +		componentPath := path.Child("components")
    +		errs = append(errs, ValidateStatefulComponent(components.Indexer, componentPath.Child("indexer"))...)
    +		errs = append(errs, ValidateStatefulComponent(components.Searcher, componentPath.Child("searcher"))...)
    +		for i := range components.Pipelines {
    +			errs = append(errs, ValidateStatefulComponent(&components.Pipelines[i].DatadogBYOCClusterStatefulComponentSpec, componentPath.Child("pipelines").Index(i))...)
    +		}
    +		if components.Metastore != nil {
    +			errs = append(errs, validateComponent(&components.Metastore.DatadogBYOCClusterComponentSpec, componentPath.Child("metastore"))...)
    +		}
    +		if components.ReadOnlyMetastore != nil {
    +			errs = append(errs, validateComponent(&components.ReadOnlyMetastore.DatadogBYOCClusterComponentSpec, componentPath.Child("readOnlyMetastore"))...)
    +		}
    +		errs = append(errs, validateComponent(components.ControlPlane, componentPath.Child("controlPlane"))...)
    +		errs = append(errs, validateComponent(components.Compactor, componentPath.Child("compactor"))...)
    +		errs = append(errs, validateComponent(components.Janitor, componentPath.Child("janitor"))...)
    +	}
    +	return errs
    +}
    +
    +func validateImageOverride(image *datadoghqv1alpha1.DatadogBYOCImageSpec, requireComplete bool, path *field.Path) field.ErrorList {
    +	if image == nil {
    +		if requireComplete {
    +			return field.ErrorList{field.Required(path, "image must be fully specified when release is omitted")}
    +		}
    +		return nil
    +	}
    +	var errs field.ErrorList
    +	if image.Tag != nil && image.Digest != nil {
    +		errs = append(errs, field.Forbidden(path, "tag and digest are mutually exclusive"))
    +	}
    +	if requireComplete {
    +		if image.Repository == nil || *image.Repository == "" {
    +			errs = append(errs, field.Required(path.Child("repository"), "repository must be non-empty when release is omitted"))
    +		}
    +		if image.Tag == nil && image.Digest == nil {
    +			errs = append(errs, field.Required(path, "tag or digest must be specified when release is omitted"))
    +		}
    +		if image.Tag != nil && *image.Tag == "" {
    +			errs = append(errs, field.Required(path.Child("tag"), "tag must be non-empty when release is omitted"))
    +		}
    +		if image.Digest != nil && *image.Digest == "" {
    +			errs = append(errs, field.Required(path.Child("digest"), "digest must be non-empty when release is omitted"))
    +		}
    +	}
    +	return errs
    +}
    +
    +// ValidateStatefulComponent is shared by BYOC components and standalone Workers.
    +func ValidateStatefulComponent(component *datadoghqv1alpha1.DatadogBYOCClusterStatefulComponentSpec, path *field.Path) field.ErrorList {
    +	if component == nil {
    +		return nil
    +	}
    +	errs := validateComponent(&component.DatadogBYOCClusterComponentSpec, path)

    Fixed in 8aac3c35: ValidateStatefulComponent now requires minReplicas/maxReplicas >= 1 and minReplicas <= maxReplicas. The validators are meant to run on the defaulted spec, so a single explicit bound is also checked against the default of the other (e.g. maxReplicas: 1 vs. the BYOC default minReplicas: 2). The reconcilers that apply defaults before validating come in a follow-up PR.

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on code on Oct 05, 2026 11:50 UTC
    Code Review
    internal/controller/datadogobservabilitypipelinesworker/validation/validation.go:1
    @@ -0,0 +1,40 @@
    +// Unless explicitly stated otherwise all files in this repository are licensed
    +// under the Apache License Version 2.0.
    +// This product includes software developed at Datadog (https://www.datadoghq.com/).
    +// Copyright 2016-present Datadog, Inc.
    +
    +// Package validation enforces Worker cross-field rules at reconciliation time.
    +// CEL/XValidation requires Kubernetes 1.25+, but the Operator's minimum supported
    +// Kubernetes version is not being raised. OperatorHub/Red Hat installations install
    +// all CRDs in the OLM bundle; they cannot omit the Worker CRD on older clusters.
    +// Keep these rules in the reconciler so the Worker does not impose a newer
    +// Kubernetes requirement on every Operator installation.
    +// See https://github.com/DataDog/datadog-operator/pull/3501#discussion_r4080491818.
    +package validation
    +
    +import (
    +	"k8s.io/apimachinery/pkg/util/validation/field"
    +
    +	datadoghqv1alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1"
    +	byocvalidation "github.com/DataDog/datadog-operator/internal/controller/datadogbyoccluster/validation"
    +)
    +
    +// ValidateWorkerSpec checks image and component rules after defaults are applied.
    +// Single-field constraints, such as minimum lengths, remain in the CRD schema.
    +func ValidateWorkerSpec(spec *datadoghqv1alpha1.DatadogObservabilityPipelinesWorkerSpec) field.ErrorList {
    +	path := field.NewPath("spec")
    +	errs := byocvalidation.ValidateStatefulComponent(&spec.DatadogBYOCClusterStatefulComponentSpec, path)

    <sub><sub>!P2 Badge</sub></sub> Require memory limits for worker components

    When a BYOC pipeline or standalone Worker supplies a non-nil resources object without limits.memory, this generic validator accepts it. Both worker paths use ValidateStatefulComponent—including the BYOC pipeline call in datadogbyoccluster/validation.go—whereas only indexer/searcher receive the memory-limit check, despite both worker API types requiring that limit for buffer sizing; add equivalent worker-specific validation before reconciliation proceeds.

    Useful? React with 👍 / 👎.

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on code on Oct 05, 2026 11:50 UTC
    Code Review
    internal/controller/datadogbyoccluster/defaults/defaults.go:1
    @@ -0,0 +1,191 @@
    +// Unless explicitly stated otherwise all files in this repository are licensed
    +// under the Apache License Version 2.0.
    +// This product includes software developed by Datadog (https://www.datadoghq.com/).
    +// Copyright 2016-present Datadog, Inc.
    +
    +package defaults
    +
    +import (
    +	autoscalingv2 "k8s.io/api/autoscaling/v2"
    +	corev1 "k8s.io/api/core/v1"
    +	"k8s.io/apimachinery/pkg/api/resource"
    +	"k8s.io/utils/ptr"
    +
    +	datadoghqv1alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1"
    +)
    +
    +// Apply returns a deep copy of the cluster with reconciliation-time defaults applied.
    +// DatadogBYOCCluster does not use a mutating admission webhook, so defaults that cannot be
    +// expressed in the shared CRD schema are applied here instead.
    +func Apply(cluster *datadoghqv1alpha1.DatadogBYOCCluster) *datadoghqv1alpha1.DatadogBYOCCluster {
    +	defaulted := cluster.DeepCopy()
    +	components := defaulted.Spec.Components
    +	applyIndexerDefaults(components.Indexer)
    +	applySearcherDefaults(components.Searcher)
    +	for i := range components.Pipelines {
    +		applyPipelineDefaults(&components.Pipelines[i].DatadogBYOCClusterPipelineComponentSpec)
    +	}
    +	applyMetastoreDefaults(components.Metastore)
    +	applyComponentDefaults(components.ControlPlane, 1, deploymentResources())
    +	applyComponentDefaults(components.Janitor, 1, deploymentResources())
    +	if components.ReadOnlyMetastore != nil {
    +		applyMetastoreDefaults(components.ReadOnlyMetastore)
    +	}
    +	if components.Compactor != nil {
    +		applyCompactorDefaults(components.Compactor)
    +	}
    +	return defaulted
    +}
    +
    +func applyPipelineDefaults(pipeline *datadoghqv1alpha1.DatadogBYOCClusterPipelineComponentSpec) {
    +	applyComponentDefaults(&pipeline.DatadogBYOCClusterComponentSpec, 2, pipelineResources())
    +	if pipeline.TerminationGracePeriodSeconds == nil {
    +		pipeline.TerminationGracePeriodSeconds = ptr.To[int64](70)
    +	}
    +	applyAutoscalingDefaults(pipeline.Autoscaling, 70, 0, 300)
    +
    +	if pipeline.Storage == nil {
    +		pipeline.Storage = &datadoghqv1alpha1.DatadogBYOCClusterStorageSpec{
    +			VolumeClaimTemplate: &datadoghqv1alpha1.DatadogBYOCClusterEmbeddedPersistentVolumeClaim{},
    +		}
    +	}
    +	if pipeline.Storage.VolumeClaimTemplate == nil {
    +		return
    +	}
    +
    +	claimSpec := &pipeline.Storage.VolumeClaimTemplate.Spec
    +	if claimSpec.AccessModes == nil {
    +		claimSpec.AccessModes = []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce}
    +	}

    <sub><sub>!P2 Badge</sub></sub> Default explicitly empty PVC access modes

    When a pipeline PVC template contains accessModes: [], decoding produces a non-nil but empty slice, so this condition skips the ReadWriteOnce default. The generated PersistentVolumeClaim then has no access modes and is rejected by the Kubernetes API; use an empty-length check here and in the identical indexer path so both omitted and explicitly empty lists receive the default.

    Useful? React with 👍 / 👎.

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on code on Oct 05, 2026 11:50 UTC
    Code Review
    internal/controller/datadogbyoccluster/validation/validation.go:1
    @@ -0,0 +1,151 @@
    +// Unless explicitly stated otherwise all files in this repository are licensed
    +// under the Apache License Version 2.0.
    +// This product includes software developed at Datadog (https://www.datadoghq.com/).
    +// Copyright 2016-present Datadog, Inc.
    +
    +// Package validation enforces BYOC cross-field rules at reconciliation time.
    +// CEL/XValidation requires Kubernetes 1.25+, but the Operator's minimum supported
    +// Kubernetes version is not being raised. OperatorHub/Red Hat installations install
    +// all CRDs in the OLM bundle; they cannot omit the BYOC CRD on older clusters.
    +// Keep these rules in the reconciler so BYOC does not impose a newer Kubernetes
    +// requirement on every Operator installation.
    +// See https://github.com/DataDog/datadog-operator/pull/3501#discussion_r4080491818.
    +package validation
    +
    +import (
    +	"fmt"
    +
    +	corev1 "k8s.io/api/core/v1"
    +	"k8s.io/apimachinery/pkg/util/validation/field"
    +
    +	datadoghqv1alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1"
    +)
    +
    +// ValidateClusterSpec checks the cross-field rules after defaults and before image resolution.
    +// Validating the defaulted spec catches conflicts between explicit and default values.
    +// Required fields and single-field constraints are enforced by the CRD schema.
    +func ValidateClusterSpec(spec *datadoghqv1alpha1.DatadogBYOCClusterSpec) field.ErrorList {
    +	path := field.NewPath("spec")
    +	var errs field.ErrorList
    +	if spec.Release == nil && spec.ImageOverrides == nil {
    +		errs = append(errs, field.Required(path, "release or imageOverrides must be specified"))
    +	}
    +	if release := spec.Release; release != nil && (release.Tag == nil) == (release.Digest == nil) {
    +		errs = append(errs, field.Invalid(path.Child("release"), nil, "exactly one of tag or digest must be specified"))
    +	}
    +	if overrides := spec.ImageOverrides; overrides != nil {
    +		// Without a release, neither image can inherit a repository or version.
    +		requireComplete := spec.Release == nil
    +		errs = append(errs, validateImageOverride(overrides.BYOC, requireComplete, path.Child("imageOverrides", "byoc"))...)
    +		errs = append(errs, validateImageOverride(overrides.ObservabilityPipelinesWorker, requireComplete, path.Child("imageOverrides", "observabilityPipelinesWorker"))...)
    +	}
    +	if spec.Provider == nil || spec.Provider.AWS == nil {
    +		errs = append(errs, field.Required(path.Child("provider", "aws"), "at least one provider must be specified"))
    +	}
    +	// Validate the global setting even if every component overrides it.
    +	errs = append(errs, validatePodDisruptionBudget(spec.Global.PodDisruptionBudget, path.Child("global", "podDisruptionBudget"))...)
    +	if components := spec.Components; components != nil {
    +		componentPath := path.Child("components")
    +		errs = append(errs, validateQuickwitStatefulComponent(components.Indexer, componentPath.Child("indexer"))...)
    +		errs = append(errs, validateQuickwitStatefulComponent(components.Searcher, componentPath.Child("searcher"))...)
    +		for i := range components.Pipelines {
    +			errs = append(errs, ValidateStatefulComponent(&components.Pipelines[i].DatadogBYOCClusterStatefulComponentSpec, componentPath.Child("pipelines").Index(i))...)
    +		}
    +		if components.Metastore != nil {
    +			errs = append(errs, validateComponent(&components.Metastore.DatadogBYOCClusterComponentSpec, componentPath.Child("metastore"))...)
    +		}
    +		if components.ReadOnlyMetastore != nil {
    +			errs = append(errs, validateComponent(&components.ReadOnlyMetastore.DatadogBYOCClusterComponentSpec, componentPath.Child("readOnlyMetastore"))...)
    +		}
    +		errs = append(errs, validateComponent(components.ControlPlane, componentPath.Child("controlPlane"))...)
    +		errs = append(errs, validateComponent(components.Compactor, componentPath.Child("compactor"))...)
    +		errs = append(errs, validateComponent(components.Janitor, componentPath.Child("janitor"))...)
    +	}
    +	return errs
    +}
    +
    +func validateImageOverride(image *datadoghqv1alpha1.DatadogBYOCImageSpec, requireComplete bool, path *field.Path) field.ErrorList {
    +	if image == nil {
    +		if requireComplete {
    +			return field.ErrorList{field.Required(path, "image must be fully specified when release is omitted")}
    +		}
    +		return nil
    +	}
    +	var errs field.ErrorList
    +	if image.Tag != nil && image.Digest != nil {
    +		errs = append(errs, field.Forbidden(path, "tag and digest are mutually exclusive"))
    +	}
    +	if requireComplete {
    +		if image.Repository == nil || *image.Repository == "" {
    +			errs = append(errs, field.Required(path.Child("repository"), "repository must be non-empty when release is omitted"))
    +		}
    +		if image.Tag == nil && image.Digest == nil {
    +			errs = append(errs, field.Required(path, "tag or digest must be specified when release is omitted"))
    +		}
    +		if image.Tag != nil && *image.Tag == "" {
    +			errs = append(errs, field.Required(path.Child("tag"), "tag must be non-empty when release is omitted"))
    +		}
    +		if image.Digest != nil && *image.Digest == "" {
    +			errs = append(errs, field.Required(path.Child("digest"), "digest must be non-empty when release is omitted"))
    +		}
    +	}
    +	return errs
    +}
    +
    +// ValidateStatefulComponent is shared by BYOC components and standalone Workers.
    +func ValidateStatefulComponent(component *datadoghqv1alpha1.DatadogBYOCClusterStatefulComponentSpec, path *field.Path) field.ErrorList {
    +	if component == nil {
    +		return nil
    +	}
    +	errs := validateComponent(&component.DatadogBYOCClusterComponentSpec, path)
    +	errs = append(errs, validateAutoscaling(component.Autoscaling, path.Child("autoscaling"))...)
    +	if storage := component.Storage; storage != nil && (storage.EmptyDir == nil) == (storage.VolumeClaimTemplate == nil) {
    +		errs = append(errs, field.Invalid(path.Child("storage"), nil, "exactly one storage type must be specified"))
    +	}
    +	return errs
    +}
    +
    +// validateQuickwitStatefulComponent also requires the memory limit used to size the Quickwit node configuration.
    +func validateQuickwitStatefulComponent(component *datadoghqv1alpha1.DatadogBYOCClusterStatefulComponentSpec, path *field.Path) field.ErrorList {
    +	if component == nil {
    +		return nil
    +	}
    +	errs := ValidateStatefulComponent(component, path)
    +	if component.Resources != nil {
    +		if _, ok := component.Resources.Limits[corev1.ResourceMemory]; !ok {
    +			errs = append(errs, field.Required(path.Child("resources", "limits", "memory"), "resources.limits.memory must be specified when resources is set"))
    +		}
    +	}
    +	return errs
    +}
    +
    +func validateAutoscaling(autoscaling *datadoghqv1alpha1.DatadogBYOCClusterAutoscalingSpec, path *field.Path) field.ErrorList {
    +	if autoscaling == nil {
    +		return nil
    +	}
    +	var errs field.ErrorList
    +	if autoscaling.MinReplicas != nil && *autoscaling.MinReplicas < 1 {
    +		errs = append(errs, field.Invalid(path.Child("minReplicas"), *autoscaling.MinReplicas, "must be greater than or equal to 1"))
    +	}
    +	if autoscaling.MaxReplicas != nil && *autoscaling.MaxReplicas < 1 {
    +		errs = append(errs, field.Invalid(path.Child("maxReplicas"), *autoscaling.MaxReplicas, "must be greater than or equal to 1"))
    +	}
    +	if autoscaling.MinReplicas != nil && autoscaling.MaxReplicas != nil && *autoscaling.MinReplicas > *autoscaling.MaxReplicas {
    +		errs = append(errs, field.Invalid(path.Child("maxReplicas"), *autoscaling.MaxReplicas, fmt.Sprintf("must be greater than or equal to minReplicas (%d)", *autoscaling.MinReplicas)))
    +	}
    +	return errs
    +}
    +
    +func validateComponent(component *datadoghqv1alpha1.DatadogBYOCClusterComponentSpec, path *field.Path) field.ErrorList {
    +	if component == nil {
    +		return nil
    +	}
    +	return validatePodDisruptionBudget(component.PodDisruptionBudget, path.Child("podDisruptionBudget"))
    +}
    +
    +func validatePodDisruptionBudget(budget *datadoghqv1alpha1.DatadogBYOCClusterPodDisruptionBudgetSpec, path *field.Path) field.ErrorList {
    +	if budget != nil && budget.MinAvailable != nil && budget.MaxUnavailable != nil {
    +		return field.ErrorList{field.Forbidden(path, "minAvailable and maxUnavailable are mutually exclusive")}
    +	}
    +	return nil

    <sub><sub>!P2 Badge</sub></sub> Validate PodDisruptionBudget value syntax

    When either budget value is an invalid percentage such as "nope" or a negative integer, the CRD admits it because these fields are unconstrained IntOrString values, and this validator accepts it whenever only one field is present. The resulting managed PodDisruptionBudget is rejected by the Kubernetes API, leaving the parent resource unable to reconcile; validate each configured value as a non-negative integer or valid percentage in addition to checking mutual exclusion.

    Useful? React with 👍 / 👎.

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on code on Oct 05, 2026 11:50 UTC
    Code Review
    internal/controller/datadogbyoccluster/validation/validation.go:1
    @@ -0,0 +1,151 @@
    +// Unless explicitly stated otherwise all files in this repository are licensed
    +// under the Apache License Version 2.0.
    +// This product includes software developed at Datadog (https://www.datadoghq.com/).
    +// Copyright 2016-present Datadog, Inc.
    +
    +// Package validation enforces BYOC cross-field rules at reconciliation time.
    +// CEL/XValidation requires Kubernetes 1.25+, but the Operator's minimum supported
    +// Kubernetes version is not being raised. OperatorHub/Red Hat installations install
    +// all CRDs in the OLM bundle; they cannot omit the BYOC CRD on older clusters.
    +// Keep these rules in the reconciler so BYOC does not impose a newer Kubernetes
    +// requirement on every Operator installation.
    +// See https://github.com/DataDog/datadog-operator/pull/3501#discussion_r4080491818.
    +package validation
    +
    +import (
    +	"fmt"
    +
    +	corev1 "k8s.io/api/core/v1"
    +	"k8s.io/apimachinery/pkg/util/validation/field"
    +
    +	datadoghqv1alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1"
    +)
    +
    +// ValidateClusterSpec checks the cross-field rules after defaults and before image resolution.
    +// Validating the defaulted spec catches conflicts between explicit and default values.
    +// Required fields and single-field constraints are enforced by the CRD schema.
    +func ValidateClusterSpec(spec *datadoghqv1alpha1.DatadogBYOCClusterSpec) field.ErrorList {
    +	path := field.NewPath("spec")
    +	var errs field.ErrorList
    +	if spec.Release == nil && spec.ImageOverrides == nil {
    +		errs = append(errs, field.Required(path, "release or imageOverrides must be specified"))
    +	}
    +	if release := spec.Release; release != nil && (release.Tag == nil) == (release.Digest == nil) {
    +		errs = append(errs, field.Invalid(path.Child("release"), nil, "exactly one of tag or digest must be specified"))

    <sub><sub>!P2 Badge</sub></sub> Reject empty release versions

    When release.tag or release.digest is present but empty, this pointer-only XOR check accepts the release. In the reviewed tree those release fields still have no minimum-length schema constraint, and resolveRelease dereferences the selected version to an empty string before attempting OCI resolution, so reconciliation fails later instead of reporting invalid configuration; require the selected value to be non-empty.

    Useful? React with 👍 / 👎.

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on Oct 05, 2026 11:50 UTC
    Reviewer

    💡 Codex Review

    Here are some automated review suggestions for this pull request.

    Reviewed commit: 8aac3c3532

    <details> <summary>ℹ️ About Codex in GitHub</summary>
    <br/>

    Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review

  • Mark a draft as ready

  • Comment "@codex review".
  • If Codex has suggestions, it will comment; otherwise it will react with 👍.

    Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

    </details>

    shuheiktgw shuheiktgw commented on code on Oct 05, 2026 11:55 UTC
    Code Review
    internal/controller/datadogbyoccluster/defaults/defaults.go:1
    @@ -0,0 +1,191 @@
    +// Unless explicitly stated otherwise all files in this repository are licensed
    +// under the Apache License Version 2.0.
    +// This product includes software developed by Datadog (https://www.datadoghq.com/).
    +// Copyright 2016-present Datadog, Inc.
    +
    +package defaults
    +
    +import (
    +	autoscalingv2 "k8s.io/api/autoscaling/v2"
    +	corev1 "k8s.io/api/core/v1"
    +	"k8s.io/apimachinery/pkg/api/resource"
    +	"k8s.io/utils/ptr"
    +
    +	datadoghqv1alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1"
    +)
    +
    +// Apply returns a deep copy of the cluster with reconciliation-time defaults applied.
    +// DatadogBYOCCluster does not use a mutating admission webhook, so defaults that cannot be
    +// expressed in the shared CRD schema are applied here instead.
    +func Apply(cluster *datadoghqv1alpha1.DatadogBYOCCluster) *datadoghqv1alpha1.DatadogBYOCCluster {
    +	defaulted := cluster.DeepCopy()
    +	components := defaulted.Spec.Components
    +	applyIndexerDefaults(components.Indexer)
    +	applySearcherDefaults(components.Searcher)
    +	for i := range components.Pipelines {
    +		applyPipelineDefaults(&components.Pipelines[i].DatadogBYOCClusterPipelineComponentSpec)
    +	}
    +	applyMetastoreDefaults(components.Metastore)
    +	applyComponentDefaults(components.ControlPlane, 1, deploymentResources())
    +	applyComponentDefaults(components.Janitor, 1, deploymentResources())
    +	if components.ReadOnlyMetastore != nil {
    +		applyMetastoreDefaults(components.ReadOnlyMetastore)
    +	}
    +	if components.Compactor != nil {
    +		applyCompactorDefaults(components.Compactor)
    +	}
    +	return defaulted
    +}
    +
    +func applyPipelineDefaults(pipeline *datadoghqv1alpha1.DatadogBYOCClusterPipelineComponentSpec) {
    +	applyComponentDefaults(&pipeline.DatadogBYOCClusterComponentSpec, 2, pipelineResources())
    +	if pipeline.TerminationGracePeriodSeconds == nil {
    +		pipeline.TerminationGracePeriodSeconds = ptr.To[int64](70)
    +	}
    +	applyAutoscalingDefaults(pipeline.Autoscaling, 70, 0, 300)
    +
    +	if pipeline.Storage == nil {
    +		pipeline.Storage = &datadoghqv1alpha1.DatadogBYOCClusterStorageSpec{
    +			VolumeClaimTemplate: &datadoghqv1alpha1.DatadogBYOCClusterEmbeddedPersistentVolumeClaim{},
    +		}
    +	}
    +	if pipeline.Storage.VolumeClaimTemplate == nil {
    +		return
    +	}
    +
    +	claimSpec := &pipeline.Storage.VolumeClaimTemplate.Spec
    +	if claimSpec.AccessModes == nil {
    +		claimSpec.AccessModes = []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce}
    +	}

    Not important

    shuheiktgw shuheiktgw commented on code on Oct 05, 2026 11:55 UTC
    Code Review
    internal/controller/datadogbyoccluster/validation/validation.go:1
    @@ -0,0 +1,151 @@
    +// Unless explicitly stated otherwise all files in this repository are licensed
    +// under the Apache License Version 2.0.
    +// This product includes software developed at Datadog (https://www.datadoghq.com/).
    +// Copyright 2016-present Datadog, Inc.
    +
    +// Package validation enforces BYOC cross-field rules at reconciliation time.
    +// CEL/XValidation requires Kubernetes 1.25+, but the Operator's minimum supported
    +// Kubernetes version is not being raised. OperatorHub/Red Hat installations install
    +// all CRDs in the OLM bundle; they cannot omit the BYOC CRD on older clusters.
    +// Keep these rules in the reconciler so BYOC does not impose a newer Kubernetes
    +// requirement on every Operator installation.
    +// See https://github.com/DataDog/datadog-operator/pull/3501#discussion_r4080491818.
    +package validation
    +
    +import (
    +	"fmt"
    +
    +	corev1 "k8s.io/api/core/v1"
    +	"k8s.io/apimachinery/pkg/util/validation/field"
    +
    +	datadoghqv1alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1"
    +)
    +
    +// ValidateClusterSpec checks the cross-field rules after defaults and before image resolution.
    +// Validating the defaulted spec catches conflicts between explicit and default values.
    +// Required fields and single-field constraints are enforced by the CRD schema.
    +func ValidateClusterSpec(spec *datadoghqv1alpha1.DatadogBYOCClusterSpec) field.ErrorList {
    +	path := field.NewPath("spec")
    +	var errs field.ErrorList
    +	if spec.Release == nil && spec.ImageOverrides == nil {
    +		errs = append(errs, field.Required(path, "release or imageOverrides must be specified"))
    +	}
    +	if release := spec.Release; release != nil && (release.Tag == nil) == (release.Digest == nil) {
    +		errs = append(errs, field.Invalid(path.Child("release"), nil, "exactly one of tag or digest must be specified"))

    Not important

    shuheiktgw shuheiktgw commented on code on Oct 05, 2026 11:55 UTC
    Code Review
    internal/controller/datadogbyoccluster/validation/validation.go:1
    @@ -0,0 +1,151 @@
    +// Unless explicitly stated otherwise all files in this repository are licensed
    +// under the Apache License Version 2.0.
    +// This product includes software developed at Datadog (https://www.datadoghq.com/).
    +// Copyright 2016-present Datadog, Inc.
    +
    +// Package validation enforces BYOC cross-field rules at reconciliation time.
    +// CEL/XValidation requires Kubernetes 1.25+, but the Operator's minimum supported
    +// Kubernetes version is not being raised. OperatorHub/Red Hat installations install
    +// all CRDs in the OLM bundle; they cannot omit the BYOC CRD on older clusters.
    +// Keep these rules in the reconciler so BYOC does not impose a newer Kubernetes
    +// requirement on every Operator installation.
    +// See https://github.com/DataDog/datadog-operator/pull/3501#discussion_r4080491818.
    +package validation
    +
    +import (
    +	"fmt"
    +
    +	corev1 "k8s.io/api/core/v1"
    +	"k8s.io/apimachinery/pkg/util/validation/field"
    +
    +	datadoghqv1alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1"
    +)
    +
    +// ValidateClusterSpec checks the cross-field rules after defaults and before image resolution.
    +// Validating the defaulted spec catches conflicts between explicit and default values.
    +// Required fields and single-field constraints are enforced by the CRD schema.
    +func ValidateClusterSpec(spec *datadoghqv1alpha1.DatadogBYOCClusterSpec) field.ErrorList {
    +	path := field.NewPath("spec")
    +	var errs field.ErrorList
    +	if spec.Release == nil && spec.ImageOverrides == nil {
    +		errs = append(errs, field.Required(path, "release or imageOverrides must be specified"))
    +	}
    +	if release := spec.Release; release != nil && (release.Tag == nil) == (release.Digest == nil) {
    +		errs = append(errs, field.Invalid(path.Child("release"), nil, "exactly one of tag or digest must be specified"))
    +	}
    +	if overrides := spec.ImageOverrides; overrides != nil {
    +		// Without a release, neither image can inherit a repository or version.
    +		requireComplete := spec.Release == nil
    +		errs = append(errs, validateImageOverride(overrides.BYOC, requireComplete, path.Child("imageOverrides", "byoc"))...)
    +		errs = append(errs, validateImageOverride(overrides.ObservabilityPipelinesWorker, requireComplete, path.Child("imageOverrides", "observabilityPipelinesWorker"))...)
    +	}
    +	if spec.Provider == nil || spec.Provider.AWS == nil {
    +		errs = append(errs, field.Required(path.Child("provider", "aws"), "at least one provider must be specified"))
    +	}
    +	// Validate the global setting even if every component overrides it.
    +	errs = append(errs, validatePodDisruptionBudget(spec.Global.PodDisruptionBudget, path.Child("global", "podDisruptionBudget"))...)
    +	if components := spec.Components; components != nil {
    +		componentPath := path.Child("components")
    +		errs = append(errs, validateQuickwitStatefulComponent(components.Indexer, componentPath.Child("indexer"))...)
    +		errs = append(errs, validateQuickwitStatefulComponent(components.Searcher, componentPath.Child("searcher"))...)
    +		for i := range components.Pipelines {
    +			errs = append(errs, ValidateStatefulComponent(&components.Pipelines[i].DatadogBYOCClusterStatefulComponentSpec, componentPath.Child("pipelines").Index(i))...)
    +		}
    +		if components.Metastore != nil {
    +			errs = append(errs, validateComponent(&components.Metastore.DatadogBYOCClusterComponentSpec, componentPath.Child("metastore"))...)
    +		}
    +		if components.ReadOnlyMetastore != nil {
    +			errs = append(errs, validateComponent(&components.ReadOnlyMetastore.DatadogBYOCClusterComponentSpec, componentPath.Child("readOnlyMetastore"))...)
    +		}
    +		errs = append(errs, validateComponent(components.ControlPlane, componentPath.Child("controlPlane"))...)
    +		errs = append(errs, validateComponent(components.Compactor, componentPath.Child("compactor"))...)
    +		errs = append(errs, validateComponent(components.Janitor, componentPath.Child("janitor"))...)
    +	}
    +	return errs
    +}
    +
    +func validateImageOverride(image *datadoghqv1alpha1.DatadogBYOCImageSpec, requireComplete bool, path *field.Path) field.ErrorList {
    +	if image == nil {
    +		if requireComplete {
    +			return field.ErrorList{field.Required(path, "image must be fully specified when release is omitted")}
    +		}
    +		return nil
    +	}
    +	var errs field.ErrorList
    +	if image.Tag != nil && image.Digest != nil {
    +		errs = append(errs, field.Forbidden(path, "tag and digest are mutually exclusive"))
    +	}
    +	if requireComplete {
    +		if image.Repository == nil || *image.Repository == "" {
    +			errs = append(errs, field.Required(path.Child("repository"), "repository must be non-empty when release is omitted"))
    +		}
    +		if image.Tag == nil && image.Digest == nil {
    +			errs = append(errs, field.Required(path, "tag or digest must be specified when release is omitted"))
    +		}
    +		if image.Tag != nil && *image.Tag == "" {
    +			errs = append(errs, field.Required(path.Child("tag"), "tag must be non-empty when release is omitted"))
    +		}
    +		if image.Digest != nil && *image.Digest == "" {
    +			errs = append(errs, field.Required(path.Child("digest"), "digest must be non-empty when release is omitted"))
    +		}
    +	}
    +	return errs
    +}
    +
    +// ValidateStatefulComponent is shared by BYOC components and standalone Workers.
    +func ValidateStatefulComponent(component *datadoghqv1alpha1.DatadogBYOCClusterStatefulComponentSpec, path *field.Path) field.ErrorList {
    +	if component == nil {
    +		return nil
    +	}
    +	errs := validateComponent(&component.DatadogBYOCClusterComponentSpec, path)
    +	errs = append(errs, validateAutoscaling(component.Autoscaling, path.Child("autoscaling"))...)
    +	if storage := component.Storage; storage != nil && (storage.EmptyDir == nil) == (storage.VolumeClaimTemplate == nil) {
    +		errs = append(errs, field.Invalid(path.Child("storage"), nil, "exactly one storage type must be specified"))
    +	}
    +	return errs
    +}
    +
    +// validateQuickwitStatefulComponent also requires the memory limit used to size the Quickwit node configuration.
    +func validateQuickwitStatefulComponent(component *datadoghqv1alpha1.DatadogBYOCClusterStatefulComponentSpec, path *field.Path) field.ErrorList {
    +	if component == nil {
    +		return nil
    +	}
    +	errs := ValidateStatefulComponent(component, path)
    +	if component.Resources != nil {
    +		if _, ok := component.Resources.Limits[corev1.ResourceMemory]; !ok {
    +			errs = append(errs, field.Required(path.Child("resources", "limits", "memory"), "resources.limits.memory must be specified when resources is set"))
    +		}
    +	}
    +	return errs
    +}
    +
    +func validateAutoscaling(autoscaling *datadoghqv1alpha1.DatadogBYOCClusterAutoscalingSpec, path *field.Path) field.ErrorList {
    +	if autoscaling == nil {
    +		return nil
    +	}
    +	var errs field.ErrorList
    +	if autoscaling.MinReplicas != nil && *autoscaling.MinReplicas < 1 {
    +		errs = append(errs, field.Invalid(path.Child("minReplicas"), *autoscaling.MinReplicas, "must be greater than or equal to 1"))
    +	}
    +	if autoscaling.MaxReplicas != nil && *autoscaling.MaxReplicas < 1 {
    +		errs = append(errs, field.Invalid(path.Child("maxReplicas"), *autoscaling.MaxReplicas, "must be greater than or equal to 1"))
    +	}
    +	if autoscaling.MinReplicas != nil && autoscaling.MaxReplicas != nil && *autoscaling.MinReplicas > *autoscaling.MaxReplicas {
    +		errs = append(errs, field.Invalid(path.Child("maxReplicas"), *autoscaling.MaxReplicas, fmt.Sprintf("must be greater than or equal to minReplicas (%d)", *autoscaling.MinReplicas)))
    +	}
    +	return errs
    +}
    +
    +func validateComponent(component *datadoghqv1alpha1.DatadogBYOCClusterComponentSpec, path *field.Path) field.ErrorList {
    +	if component == nil {
    +		return nil
    +	}
    +	return validatePodDisruptionBudget(component.PodDisruptionBudget, path.Child("podDisruptionBudget"))
    +}
    +
    +func validatePodDisruptionBudget(budget *datadoghqv1alpha1.DatadogBYOCClusterPodDisruptionBudgetSpec, path *field.Path) field.ErrorList {
    +	if budget != nil && budget.MinAvailable != nil && budget.MaxUnavailable != nil {
    +		return field.ErrorList{field.Forbidden(path, "minAvailable and maxUnavailable are mutually exclusive")}
    +	}
    +	return nil

    Not important

    datadog-datadog-prod-us1-2[bot] datadog-datadog-prod-us1-2[bot] commented on Oct 05, 2026 11:56 UTC
    Bot

    <a target='_blank' href='https://app.datadoghq.com/ci/code-coverage/github.com%2Fdatadog%2Fdatadog-operator/pull-requests/3554'><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.datadoghq.com/static/images/pr_comments/software_delivery/badges_header/code-coverage-ok.svg"/><img src="https://static.datadoghq.com/static/images/pr_comments/software_delivery/badges_header/code-coverage-ok-light.svg" alt="Code Coverage" align="center" /></picture></a>

    🎯 Code Coverage (<a target='_blank' href='https://app.datadoghq.com/ci/code-coverage/github.com%2Fdatadog%2Fdatadog-operator/pull-requests/3554'>details</a>)<br>• <strong><span title="Percentage of modified executable lines covered by tests in this PR">Patch Coverage</span></strong>: 100.00%<br>• <strong><span title="Percentage of all executable lines covered by tests in the entire codebase">Overall Coverage</span></strong>: 53.02% <span title="Change in overall coverage compared to the base branch">(+0.50%)</span><br>

    <sub>
    This comment will be updated automatically if new data arrives. <br />
    🔗 Commit SHA: 98e9c6b | <a href="https://docs.datadoghq.com/integrations/guide/source-code-integration/#pr-comments">Docs</a> | Give us <a href="https://dd.enterprise.slack.com/archives/C07E3U2QRMM">feedback</a>!
    </sub>

    shuheiktgw shuheiktgw commented on code on Oct 05, 2026 12:03 UTC
    Code Review
    internal/controller/datadogobservabilitypipelinesworker/validation/validation.go:1
    @@ -0,0 +1,40 @@
    +// Unless explicitly stated otherwise all files in this repository are licensed
    +// under the Apache License Version 2.0.
    +// This product includes software developed at Datadog (https://www.datadoghq.com/).
    +// Copyright 2016-present Datadog, Inc.
    +
    +// Package validation enforces Worker cross-field rules at reconciliation time.
    +// CEL/XValidation requires Kubernetes 1.25+, but the Operator's minimum supported
    +// Kubernetes version is not being raised. OperatorHub/Red Hat installations install
    +// all CRDs in the OLM bundle; they cannot omit the Worker CRD on older clusters.
    +// Keep these rules in the reconciler so the Worker does not impose a newer
    +// Kubernetes requirement on every Operator installation.
    +// See https://github.com/DataDog/datadog-operator/pull/3501#discussion_r4080491818.
    +package validation
    +
    +import (
    +	"k8s.io/apimachinery/pkg/util/validation/field"
    +
    +	datadoghqv1alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1"
    +	byocvalidation "github.com/DataDog/datadog-operator/internal/controller/datadogbyoccluster/validation"
    +)
    +
    +// ValidateWorkerSpec checks image and component rules after defaults are applied.
    +// Single-field constraints, such as minimum lengths, remain in the CRD schema.
    +func ValidateWorkerSpec(spec *datadoghqv1alpha1.DatadogObservabilityPipelinesWorkerSpec) field.ErrorList {
    +	path := field.NewPath("spec")
    +	errs := byocvalidation.ValidateStatefulComponent(&spec.DatadogBYOCClusterStatefulComponentSpec, path)

    The Operator does not use the Worker memory limit for buffer sizing; neither the Worker nor the BYOC pipeline reads it. Only the Indexer and Searcher size their Quickwit configuration from it, so the check stays scoped to them. The API doc note was stale and was removed in eb7da580.

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on code on Oct 05, 2026 12:11 UTC
    Code Review
    internal/controller/datadogbyoccluster/defaults/defaults.go:1
    @@ -0,0 +1,191 @@
    +// Unless explicitly stated otherwise all files in this repository are licensed
    +// under the Apache License Version 2.0.
    +// This product includes software developed by Datadog (https://www.datadoghq.com/).
    +// Copyright 2016-present Datadog, Inc.
    +
    +package defaults
    +
    +import (
    +	autoscalingv2 "k8s.io/api/autoscaling/v2"
    +	corev1 "k8s.io/api/core/v1"
    +	"k8s.io/apimachinery/pkg/api/resource"
    +	"k8s.io/utils/ptr"
    +
    +	datadoghqv1alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1"
    +)
    +
    +// Apply returns a deep copy of the cluster with reconciliation-time defaults applied.
    +// DatadogBYOCCluster does not use a mutating admission webhook, so defaults that cannot be
    +// expressed in the shared CRD schema are applied here instead.
    +func Apply(cluster *datadoghqv1alpha1.DatadogBYOCCluster) *datadoghqv1alpha1.DatadogBYOCCluster {
    +	defaulted := cluster.DeepCopy()
    +	components := defaulted.Spec.Components
    +	applyIndexerDefaults(components.Indexer)
    +	applySearcherDefaults(components.Searcher)
    +	for i := range components.Pipelines {
    +		applyPipelineDefaults(&components.Pipelines[i].DatadogBYOCClusterPipelineComponentSpec)
    +	}
    +	applyMetastoreDefaults(components.Metastore)
    +	applyComponentDefaults(components.ControlPlane, 1, deploymentResources())
    +	applyComponentDefaults(components.Janitor, 1, deploymentResources())
    +	if components.ReadOnlyMetastore != nil {
    +		applyMetastoreDefaults(components.ReadOnlyMetastore)
    +	}
    +	if components.Compactor != nil {
    +		applyCompactorDefaults(components.Compactor)
    +	}
    +	return defaulted
    +}
    +
    +func applyPipelineDefaults(pipeline *datadoghqv1alpha1.DatadogBYOCClusterPipelineComponentSpec) {
    +	applyComponentDefaults(&pipeline.DatadogBYOCClusterComponentSpec, 2, pipelineResources())
    +	if pipeline.TerminationGracePeriodSeconds == nil {
    +		pipeline.TerminationGracePeriodSeconds = ptr.To[int64](70)
    +	}
    +	applyAutoscalingDefaults(pipeline.Autoscaling, 70, 0, 300)
    +
    +	if pipeline.Storage == nil {
    +		pipeline.Storage = &datadoghqv1alpha1.DatadogBYOCClusterStorageSpec{
    +			VolumeClaimTemplate: &datadoghqv1alpha1.DatadogBYOCClusterEmbeddedPersistentVolumeClaim{},
    +		}
    +	}
    +	if pipeline.Storage.VolumeClaimTemplate == nil {
    +		return
    +	}
    +
    +	claimSpec := &pipeline.Storage.VolumeClaimTemplate.Spec
    +	if claimSpec.AccessModes == nil {
    +		claimSpec.AccessModes = []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce}
    +	}
    +	if claimSpec.Resources.Requests == nil {
    +		claimSpec.Resources.Requests = corev1.ResourceList{}
    +	}
    +	if _, found := claimSpec.Resources.Requests[corev1.ResourceStorage]; !found {
    +		claimSpec.Resources.Requests[corev1.ResourceStorage] = resource.MustParse("30Gi")
    +	}
    +}
    +
    +func applyIndexerDefaults(indexer *datadoghqv1alpha1.DatadogBYOCClusterStatefulComponentSpec) {
    +	applyComponentDefaults(&indexer.DatadogBYOCClusterComponentSpec, 2, statefulResources())
    +	if indexer.TerminationGracePeriodSeconds == nil {
    +		indexer.TerminationGracePeriodSeconds = ptr.To[int64](300)
    +	}
    +	applyAutoscalingDefaults(indexer.Autoscaling, 70, 0, 300)
    +
    +	if indexer.Storage == nil {
    +		indexer.Storage = &datadoghqv1alpha1.DatadogBYOCClusterStorageSpec{
    +			VolumeClaimTemplate: &datadoghqv1alpha1.DatadogBYOCClusterEmbeddedPersistentVolumeClaim{},
    +		}
    +	}
    +	if indexer.Storage.VolumeClaimTemplate == nil {
    +		return
    +	}
    +
    +	claimSpec := &indexer.Storage.VolumeClaimTemplate.Spec
    +	if claimSpec.AccessModes == nil {
    +		claimSpec.AccessModes = []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce}
    +	}
    +	if claimSpec.Resources.Requests == nil {
    +		claimSpec.Resources.Requests = corev1.ResourceList{}
    +	}
    +	if _, found := claimSpec.Resources.Requests[corev1.ResourceStorage]; !found {
    +		claimSpec.Resources.Requests[corev1.ResourceStorage] = resource.MustParse("30Gi")
    +	}
    +}
    +
    +func applySearcherDefaults(searcher *datadoghqv1alpha1.DatadogBYOCClusterStatefulComponentSpec) {
    +	applyComponentDefaults(&searcher.DatadogBYOCClusterComponentSpec, 2, statefulResources())
    +	applyAutoscalingDefaults(searcher.Autoscaling, 50, 60, 300)
    +	if searcher.Storage == nil {
    +		searcher.Storage = &datadoghqv1alpha1.DatadogBYOCClusterStorageSpec{
    +			EmptyDir: &corev1.EmptyDirVolumeSource{},
    +		}
    +	}
    +}
    +
    +func applyMetastoreDefaults(metastore *datadoghqv1alpha1.DatadogBYOCClusterMetastoreComponentSpec) {
    +	applyComponentDefaults(&metastore.DatadogBYOCClusterComponentSpec, 2, deploymentResources())
    +}
    +
    +func applyCompactorDefaults(compactor *datadoghqv1alpha1.DatadogBYOCClusterComponentSpec) {
    +	applyComponentDefaults(compactor, 1, nil)
    +	if compactor.TerminationGracePeriodSeconds == nil {
    +		compactor.TerminationGracePeriodSeconds = ptr.To[int64](60)
    +	}
    +}
    +
    +func applyComponentDefaults(component *datadoghqv1alpha1.DatadogBYOCClusterComponentSpec, replicas int32, resources *corev1.ResourceRequirements) {
    +	if component.Replicas == nil {
    +		component.Replicas = new(replicas)
    +	}
    +	if component.Resources == nil && resources != nil {
    +		component.Resources = resources.DeepCopy()

    <sub><sub>!P2 Badge</sub></sub> Preserve a CPU request for default CPU autoscaling

    When autoscaling is enabled with omitted metrics but the user supplies any non-nil partial resources object without requests.cpu, this branch preserves that object while applyAutoscalingDefaults injects a CPU-utilization metric. Kubernetes cannot calculate utilization for a pod whose relevant container has no CPU request, so the HPA remains unable to scale; the standalone Worker defaulting path has the same interaction. Merge the default CPU request when selecting this metric, or reject/default this combination.

    Useful? React with 👍 / 👎.

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on code on Oct 05, 2026 12:11 UTC
    Code Review
    internal/controller/datadogobservabilitypipelinesworker/defaults/defaults.go:1
    @@ -0,0 +1,70 @@
    +// Unless explicitly stated otherwise all files in this repository are licensed
    +// under the Apache License Version 2.0.
    +// This product includes software developed at Datadog (https://www.datadoghq.com/).
    +// Copyright 2016-present Datadog, Inc.
    +
    +// Package defaults applies reconciliation-time defaults to Observability Pipelines Workers.
    +package defaults
    +
    +import (
    +	autoscalingv2 "k8s.io/api/autoscaling/v2"
    +	corev1 "k8s.io/api/core/v1"
    +	"k8s.io/apimachinery/pkg/api/resource"
    +	"k8s.io/utils/ptr"
    +
    +	datadoghqv1alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1"
    +)
    +
    +// Apply returns a deep copy of the worker with reconciliation-time defaults applied.
    +func Apply(worker *datadoghqv1alpha1.DatadogObservabilityPipelinesWorker) *datadoghqv1alpha1.DatadogObservabilityPipelinesWorker {
    +	defaulted := worker.DeepCopy()
    +	component := &defaulted.Spec.DatadogBYOCClusterPipelineComponentSpec
    +
    +	if component.Replicas == nil {
    +		component.Replicas = ptr.To[int32](1)
    +	}
    +	if component.Resources == nil {
    +		component.Resources = &corev1.ResourceRequirements{
    +			Requests: corev1.ResourceList{
    +				corev1.ResourceCPU:    resource.MustParse("2"),
    +				corev1.ResourceMemory: resource.MustParse("4Gi"),
    +			},
    +		}
    +	}
    +	if component.TerminationGracePeriodSeconds == nil {
    +		component.TerminationGracePeriodSeconds = ptr.To[int64](70)
    +	}
    +	applyAutoscalingDefaults(component.Autoscaling)
    +
    +	if component.Storage == nil {
    +		component.Storage = &datadoghqv1alpha1.DatadogBYOCClusterStorageSpec{
    +			EmptyDir: &corev1.EmptyDirVolumeSource{},
    +		}

    <sub><sub>!P2 Badge</sub></sub> Default fields inside standalone Worker PVC templates

    When a standalone Worker selects storage.volumeClaimTemplate: {}, this condition skips storage defaulting entirely, and no later Worker code supplies an access mode or storage request. ValidateStatefulComponent accepts the template because exactly one storage type is present, but the resulting PVC is rejected for lacking its required access modes and requested capacity; apply the same ReadWriteOnce/capacity defaults used for BYOC pipeline claims, or validate that an opted-in Worker claim is complete.

    Useful? React with 👍 / 👎.

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on Oct 05, 2026 12:11 UTC
    Reviewer

    💡 Codex Review

    Here are some automated review suggestions for this pull request.

    Reviewed commit: eb7da580e2

    <details> <summary>ℹ️ About Codex in GitHub</summary>
    <br/>

    Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review

  • Mark a draft as ready

  • Comment "@codex review".
  • If Codex has suggestions, it will comment; otherwise it will react with 👍.

    Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

    </details>

    levan-m levan-m commented on code on Oct 05, 2026 20:55 UTC
    Code Review
    internal/controller/datadogbyoccluster/defaults/defaults.go:1
    @@ -0,0 +1,191 @@
    +// Unless explicitly stated otherwise all files in this repository are licensed
    +// under the Apache License Version 2.0.
    +// This product includes software developed by Datadog (https://www.datadoghq.com/).
    +// Copyright 2016-present Datadog, Inc.
    +
    +package defaults
    +
    +import (
    +	autoscalingv2 "k8s.io/api/autoscaling/v2"
    +	corev1 "k8s.io/api/core/v1"
    +	"k8s.io/apimachinery/pkg/api/resource"
    +	"k8s.io/utils/ptr"
    +
    +	datadoghqv1alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1"
    +)
    +
    +// Apply returns a deep copy of the cluster with reconciliation-time defaults applied.
    +// DatadogBYOCCluster does not use a mutating admission webhook, so defaults that cannot be
    +// expressed in the shared CRD schema are applied here instead.
    +func Apply(cluster *datadoghqv1alpha1.DatadogBYOCCluster) *datadoghqv1alpha1.DatadogBYOCCluster {
    +	defaulted := cluster.DeepCopy()
    +	components := defaulted.Spec.Components
    +	applyIndexerDefaults(components.Indexer)
    +	applySearcherDefaults(components.Searcher)
    +	for i := range components.Pipelines {
    +		applyPipelineDefaults(&components.Pipelines[i].DatadogBYOCClusterPipelineComponentSpec)
    +	}
    +	applyMetastoreDefaults(components.Metastore)
    +	applyComponentDefaults(components.ControlPlane, 1, deploymentResources())
    +	applyComponentDefaults(components.Janitor, 1, deploymentResources())
    +	if components.ReadOnlyMetastore != nil {
    +		applyMetastoreDefaults(components.ReadOnlyMetastore)
    +	}
    +	if components.Compactor != nil {
    +		applyCompactorDefaults(components.Compactor)
    +	}
    +	return defaulted
    +}
    +
    +func applyPipelineDefaults(pipeline *datadoghqv1alpha1.DatadogBYOCClusterPipelineComponentSpec) {
    +	applyComponentDefaults(&pipeline.DatadogBYOCClusterComponentSpec, 2, pipelineResources())
    +	if pipeline.TerminationGracePeriodSeconds == nil {
    +		pipeline.TerminationGracePeriodSeconds = ptr.To[int64](70)
    +	}
    +	applyAutoscalingDefaults(pipeline.Autoscaling, 70, 0, 300)
    +
    +	if pipeline.Storage == nil {
    +		pipeline.Storage = &datadoghqv1alpha1.DatadogBYOCClusterStorageSpec{
    +			VolumeClaimTemplate: &datadoghqv1alpha1.DatadogBYOCClusterEmbeddedPersistentVolumeClaim{},
    +		}
    +	}
    +	if pipeline.Storage.VolumeClaimTemplate == nil {
    +		return
    +	}
    +
    +	claimSpec := &pipeline.Storage.VolumeClaimTemplate.Spec
    +	if claimSpec.AccessModes == nil {
    +		claimSpec.AccessModes = []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce}
    +	}
    +	if claimSpec.Resources.Requests == nil {
    +		claimSpec.Resources.Requests = corev1.ResourceList{}
    +	}
    +	if _, found := claimSpec.Resources.Requests[corev1.ResourceStorage]; !found {
    +		claimSpec.Resources.Requests[corev1.ResourceStorage] = resource.MustParse("30Gi")
    +	}
    +}
    +
    +func applyIndexerDefaults(indexer *datadoghqv1alpha1.DatadogBYOCClusterStatefulComponentSpec) {
    +	applyComponentDefaults(&indexer.DatadogBYOCClusterComponentSpec, 2, statefulResources())
    +	if indexer.TerminationGracePeriodSeconds == nil {
    +		indexer.TerminationGracePeriodSeconds = ptr.To[int64](300)
    +	}
    +	applyAutoscalingDefaults(indexer.Autoscaling, 70, 0, 300)
    +
    +	if indexer.Storage == nil {
    +		indexer.Storage = &datadoghqv1alpha1.DatadogBYOCClusterStorageSpec{
    +			VolumeClaimTemplate: &datadoghqv1alpha1.DatadogBYOCClusterEmbeddedPersistentVolumeClaim{},
    +		}
    +	}
    +	if indexer.Storage.VolumeClaimTemplate == nil {
    +		return
    +	}
    +
    +	claimSpec := &indexer.Storage.VolumeClaimTemplate.Spec
    +	if claimSpec.AccessModes == nil {
    +		claimSpec.AccessModes = []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce}
    +	}
    +	if claimSpec.Resources.Requests == nil {
    +		claimSpec.Resources.Requests = corev1.ResourceList{}
    +	}
    +	if _, found := claimSpec.Resources.Requests[corev1.ResourceStorage]; !found {
    +		claimSpec.Resources.Requests[corev1.ResourceStorage] = resource.MustParse("30Gi")
    +	}
    +}
    +
    +func applySearcherDefaults(searcher *datadoghqv1alpha1.DatadogBYOCClusterStatefulComponentSpec) {
    +	applyComponentDefaults(&searcher.DatadogBYOCClusterComponentSpec, 2, statefulResources())
    +	applyAutoscalingDefaults(searcher.Autoscaling, 50, 60, 300)
    +	if searcher.Storage == nil {
    +		searcher.Storage = &datadoghqv1alpha1.DatadogBYOCClusterStorageSpec{
    +			EmptyDir: &corev1.EmptyDirVolumeSource{},
    +		}
    +	}
    +}
    +
    +func applyMetastoreDefaults(metastore *datadoghqv1alpha1.DatadogBYOCClusterMetastoreComponentSpec) {
    +	applyComponentDefaults(&metastore.DatadogBYOCClusterComponentSpec, 2, deploymentResources())
    +}
    +
    +func applyCompactorDefaults(compactor *datadoghqv1alpha1.DatadogBYOCClusterComponentSpec) {
    +	applyComponentDefaults(compactor, 1, nil)
    +	if compactor.TerminationGracePeriodSeconds == nil {
    +		compactor.TerminationGracePeriodSeconds = ptr.To[int64](60)
    +	}
    +}
    +
    +func applyComponentDefaults(component *datadoghqv1alpha1.DatadogBYOCClusterComponentSpec, replicas int32, resources *corev1.ResourceRequirements) {
    +	if component.Replicas == nil {
    +		component.Replicas = new(replicas)

    should this be set if autoscaling is also configured?

    levan-m levan-m approved these changes on Oct 05, 2026 20:57 UTC
    Approved Reviewer

    Approved these changes.

    Mallets Mallets commented on code on Oct 06, 2026 07:43 UTC
    Code Review
    api/datadoghq/v1alpha1/datadogbyoccluster_types.go:1
    @@ -261,10 +261,12 @@ type DatadogBYOCClusterComponentsSpec struct {
     	ReadOnlyMetastore *DatadogBYOCClusterMetastoreComponentSpec `json:"readOnlyMetastore,omitempty"`
     
     	// Indexer configures the Indexer workload.
    +	// When Resources is specified, its memory limit is required for Quickwit node configuration sizing.

    nit: I don't think we should by talking about Quickwit here.

    Mallets Mallets commented on code on Oct 06, 2026 07:44 UTC
    Code Review
    api/datadoghq/v1alpha1/datadogbyoccluster_types.go:1
    @@ -261,10 +261,12 @@ type DatadogBYOCClusterComponentsSpec struct {
     	ReadOnlyMetastore *DatadogBYOCClusterMetastoreComponentSpec `json:"readOnlyMetastore,omitempty"`
     
     	// Indexer configures the Indexer workload.
    +	// When Resources is specified, its memory limit is required for Quickwit node configuration sizing.
     	// +kubebuilder:validation:Required
     	Indexer *DatadogBYOCClusterStatefulComponentSpec `json:"indexer,omitempty"`
     
     	// Searcher configures the Searcher workload.
    +	// When Resources is specified, its memory limit is required for Quickwit node configuration sizing.

    nit: I don't think we should by talking about Quickwit here.

    Mallets Mallets commented on code on Oct 06, 2026 07:49 UTC
    Code Review
    internal/controller/datadogbyoccluster/defaults/defaults.go:1
    @@ -0,0 +1,191 @@
    +// Unless explicitly stated otherwise all files in this repository are licensed
    +// under the Apache License Version 2.0.
    +// This product includes software developed by Datadog (https://www.datadoghq.com/).
    +// Copyright 2016-present Datadog, Inc.
    +
    +package defaults
    +
    +import (
    +	autoscalingv2 "k8s.io/api/autoscaling/v2"
    +	corev1 "k8s.io/api/core/v1"
    +	"k8s.io/apimachinery/pkg/api/resource"
    +	"k8s.io/utils/ptr"
    +
    +	datadoghqv1alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1"
    +)
    +
    +// Apply returns a deep copy of the cluster with reconciliation-time defaults applied.
    +// DatadogBYOCCluster does not use a mutating admission webhook, so defaults that cannot be
    +// expressed in the shared CRD schema are applied here instead.
    +func Apply(cluster *datadoghqv1alpha1.DatadogBYOCCluster) *datadoghqv1alpha1.DatadogBYOCCluster {
    +	defaulted := cluster.DeepCopy()
    +	components := defaulted.Spec.Components
    +	applyIndexerDefaults(components.Indexer)
    +	applySearcherDefaults(components.Searcher)
    +	for i := range components.Pipelines {
    +		applyPipelineDefaults(&components.Pipelines[i].DatadogBYOCClusterPipelineComponentSpec)
    +	}
    +	applyMetastoreDefaults(components.Metastore)
    +	applyComponentDefaults(components.ControlPlane, 1, deploymentResources())
    +	applyComponentDefaults(components.Janitor, 1, deploymentResources())
    +	if components.ReadOnlyMetastore != nil {
    +		applyMetastoreDefaults(components.ReadOnlyMetastore)
    +	}
    +	if components.Compactor != nil {
    +		applyCompactorDefaults(components.Compactor)
    +	}
    +	return defaulted
    +}
    +
    +func applyPipelineDefaults(pipeline *datadoghqv1alpha1.DatadogBYOCClusterPipelineComponentSpec) {
    +	applyComponentDefaults(&pipeline.DatadogBYOCClusterComponentSpec, 2, pipelineResources())
    +	if pipeline.TerminationGracePeriodSeconds == nil {
    +		pipeline.TerminationGracePeriodSeconds = ptr.To[int64](70)
    +	}
    +	applyAutoscalingDefaults(pipeline.Autoscaling, 70, 0, 300)
    +
    +	if pipeline.Storage == nil {
    +		pipeline.Storage = &datadoghqv1alpha1.DatadogBYOCClusterStorageSpec{
    +			VolumeClaimTemplate: &datadoghqv1alpha1.DatadogBYOCClusterEmbeddedPersistentVolumeClaim{},
    +		}
    +	}
    +	if pipeline.Storage.VolumeClaimTemplate == nil {
    +		return
    +	}
    +
    +	claimSpec := &pipeline.Storage.VolumeClaimTemplate.Spec
    +	if claimSpec.AccessModes == nil {
    +		claimSpec.AccessModes = []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce}
    +	}
    +	if claimSpec.Resources.Requests == nil {
    +		claimSpec.Resources.Requests = corev1.ResourceList{}
    +	}
    +	if _, found := claimSpec.Resources.Requests[corev1.ResourceStorage]; !found {
    +		claimSpec.Resources.Requests[corev1.ResourceStorage] = resource.MustParse("30Gi")
    +	}
    +}
    +
    +func applyIndexerDefaults(indexer *datadoghqv1alpha1.DatadogBYOCClusterStatefulComponentSpec) {
    +	applyComponentDefaults(&indexer.DatadogBYOCClusterComponentSpec, 2, statefulResources())
    +	if indexer.TerminationGracePeriodSeconds == nil {
    +		indexer.TerminationGracePeriodSeconds = ptr.To[int64](300)

    nit: it would be good to have all the constant values defined and grouped at the beginning of the file.
    It makes eyeballing values easier compared to look into the code.

    Mallets Mallets commented on code on Oct 06, 2026 07:55 UTC
    Code Review
    internal/controller/datadogbyoccluster/defaults/defaults.go:1
    @@ -0,0 +1,191 @@
    +// Unless explicitly stated otherwise all files in this repository are licensed
    +// under the Apache License Version 2.0.
    +// This product includes software developed by Datadog (https://www.datadoghq.com/).
    +// Copyright 2016-present Datadog, Inc.
    +
    +package defaults
    +
    +import (
    +	autoscalingv2 "k8s.io/api/autoscaling/v2"
    +	corev1 "k8s.io/api/core/v1"
    +	"k8s.io/apimachinery/pkg/api/resource"
    +	"k8s.io/utils/ptr"
    +
    +	datadoghqv1alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1"
    +)
    +
    +// Apply returns a deep copy of the cluster with reconciliation-time defaults applied.
    +// DatadogBYOCCluster does not use a mutating admission webhook, so defaults that cannot be
    +// expressed in the shared CRD schema are applied here instead.
    +func Apply(cluster *datadoghqv1alpha1.DatadogBYOCCluster) *datadoghqv1alpha1.DatadogBYOCCluster {
    +	defaulted := cluster.DeepCopy()
    +	components := defaulted.Spec.Components
    +	applyIndexerDefaults(components.Indexer)
    +	applySearcherDefaults(components.Searcher)
    +	for i := range components.Pipelines {
    +		applyPipelineDefaults(&components.Pipelines[i].DatadogBYOCClusterPipelineComponentSpec)
    +	}
    +	applyMetastoreDefaults(components.Metastore)
    +	applyComponentDefaults(components.ControlPlane, 1, deploymentResources())
    +	applyComponentDefaults(components.Janitor, 1, deploymentResources())
    +	if components.ReadOnlyMetastore != nil {
    +		applyMetastoreDefaults(components.ReadOnlyMetastore)
    +	}
    +	if components.Compactor != nil {
    +		applyCompactorDefaults(components.Compactor)
    +	}
    +	return defaulted
    +}
    +
    +func applyPipelineDefaults(pipeline *datadoghqv1alpha1.DatadogBYOCClusterPipelineComponentSpec) {
    +	applyComponentDefaults(&pipeline.DatadogBYOCClusterComponentSpec, 2, pipelineResources())
    +	if pipeline.TerminationGracePeriodSeconds == nil {
    +		pipeline.TerminationGracePeriodSeconds = ptr.To[int64](70)
    +	}
    +	applyAutoscalingDefaults(pipeline.Autoscaling, 70, 0, 300)
    +
    +	if pipeline.Storage == nil {
    +		pipeline.Storage = &datadoghqv1alpha1.DatadogBYOCClusterStorageSpec{
    +			VolumeClaimTemplate: &datadoghqv1alpha1.DatadogBYOCClusterEmbeddedPersistentVolumeClaim{},
    +		}
    +	}
    +	if pipeline.Storage.VolumeClaimTemplate == nil {
    +		return
    +	}
    +
    +	claimSpec := &pipeline.Storage.VolumeClaimTemplate.Spec
    +	if claimSpec.AccessModes == nil {
    +		claimSpec.AccessModes = []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce}
    +	}
    +	if claimSpec.Resources.Requests == nil {
    +		claimSpec.Resources.Requests = corev1.ResourceList{}
    +	}
    +	if _, found := claimSpec.Resources.Requests[corev1.ResourceStorage]; !found {
    +		claimSpec.Resources.Requests[corev1.ResourceStorage] = resource.MustParse("30Gi")
    +	}
    +}
    +
    +func applyIndexerDefaults(indexer *datadoghqv1alpha1.DatadogBYOCClusterStatefulComponentSpec) {
    +	applyComponentDefaults(&indexer.DatadogBYOCClusterComponentSpec, 2, statefulResources())
    +	if indexer.TerminationGracePeriodSeconds == nil {
    +		indexer.TerminationGracePeriodSeconds = ptr.To[int64](300)
    +	}
    +	applyAutoscalingDefaults(indexer.Autoscaling, 70, 0, 300)
    +
    +	if indexer.Storage == nil {
    +		indexer.Storage = &datadoghqv1alpha1.DatadogBYOCClusterStorageSpec{
    +			VolumeClaimTemplate: &datadoghqv1alpha1.DatadogBYOCClusterEmbeddedPersistentVolumeClaim{},
    +		}
    +	}
    +	if indexer.Storage.VolumeClaimTemplate == nil {
    +		return
    +	}
    +
    +	claimSpec := &indexer.Storage.VolumeClaimTemplate.Spec
    +	if claimSpec.AccessModes == nil {
    +		claimSpec.AccessModes = []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce}
    +	}
    +	if claimSpec.Resources.Requests == nil {
    +		claimSpec.Resources.Requests = corev1.ResourceList{}
    +	}
    +	if _, found := claimSpec.Resources.Requests[corev1.ResourceStorage]; !found {
    +		claimSpec.Resources.Requests[corev1.ResourceStorage] = resource.MustParse("30Gi")

    A default storage size is requested even in the case the PVC storage has a smaller limits configured. This will be rejected later by k8s so it should be ok.

    Mallets Mallets approved these changes on Oct 06, 2026 07:56 UTC
    Approved Reviewer

    Approved these changes.

    shuheiktgw shuheiktgw commented on code on Oct 06, 2026 08:17 UTC
    Code Review
    internal/controller/datadogbyoccluster/defaults/defaults.go:1
    @@ -0,0 +1,191 @@
    +// Unless explicitly stated otherwise all files in this repository are licensed
    +// under the Apache License Version 2.0.
    +// This product includes software developed by Datadog (https://www.datadoghq.com/).
    +// Copyright 2016-present Datadog, Inc.
    +
    +package defaults
    +
    +import (
    +	autoscalingv2 "k8s.io/api/autoscaling/v2"
    +	corev1 "k8s.io/api/core/v1"
    +	"k8s.io/apimachinery/pkg/api/resource"
    +	"k8s.io/utils/ptr"
    +
    +	datadoghqv1alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1"
    +)
    +
    +// Apply returns a deep copy of the cluster with reconciliation-time defaults applied.
    +// DatadogBYOCCluster does not use a mutating admission webhook, so defaults that cannot be
    +// expressed in the shared CRD schema are applied here instead.
    +func Apply(cluster *datadoghqv1alpha1.DatadogBYOCCluster) *datadoghqv1alpha1.DatadogBYOCCluster {
    +	defaulted := cluster.DeepCopy()
    +	components := defaulted.Spec.Components
    +	applyIndexerDefaults(components.Indexer)
    +	applySearcherDefaults(components.Searcher)
    +	for i := range components.Pipelines {
    +		applyPipelineDefaults(&components.Pipelines[i].DatadogBYOCClusterPipelineComponentSpec)
    +	}
    +	applyMetastoreDefaults(components.Metastore)
    +	applyComponentDefaults(components.ControlPlane, 1, deploymentResources())
    +	applyComponentDefaults(components.Janitor, 1, deploymentResources())
    +	if components.ReadOnlyMetastore != nil {
    +		applyMetastoreDefaults(components.ReadOnlyMetastore)
    +	}
    +	if components.Compactor != nil {
    +		applyCompactorDefaults(components.Compactor)
    +	}
    +	return defaulted
    +}
    +
    +func applyPipelineDefaults(pipeline *datadoghqv1alpha1.DatadogBYOCClusterPipelineComponentSpec) {
    +	applyComponentDefaults(&pipeline.DatadogBYOCClusterComponentSpec, 2, pipelineResources())
    +	if pipeline.TerminationGracePeriodSeconds == nil {
    +		pipeline.TerminationGracePeriodSeconds = ptr.To[int64](70)
    +	}
    +	applyAutoscalingDefaults(pipeline.Autoscaling, 70, 0, 300)
    +
    +	if pipeline.Storage == nil {
    +		pipeline.Storage = &datadoghqv1alpha1.DatadogBYOCClusterStorageSpec{
    +			VolumeClaimTemplate: &datadoghqv1alpha1.DatadogBYOCClusterEmbeddedPersistentVolumeClaim{},
    +		}
    +	}
    +	if pipeline.Storage.VolumeClaimTemplate == nil {
    +		return
    +	}
    +
    +	claimSpec := &pipeline.Storage.VolumeClaimTemplate.Spec
    +	if claimSpec.AccessModes == nil {
    +		claimSpec.AccessModes = []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce}
    +	}
    +	if claimSpec.Resources.Requests == nil {
    +		claimSpec.Resources.Requests = corev1.ResourceList{}
    +	}
    +	if _, found := claimSpec.Resources.Requests[corev1.ResourceStorage]; !found {
    +		claimSpec.Resources.Requests[corev1.ResourceStorage] = resource.MustParse("30Gi")
    +	}
    +}
    +
    +func applyIndexerDefaults(indexer *datadoghqv1alpha1.DatadogBYOCClusterStatefulComponentSpec) {
    +	applyComponentDefaults(&indexer.DatadogBYOCClusterComponentSpec, 2, statefulResources())
    +	if indexer.TerminationGracePeriodSeconds == nil {
    +		indexer.TerminationGracePeriodSeconds = ptr.To[int64](300)
    +	}
    +	applyAutoscalingDefaults(indexer.Autoscaling, 70, 0, 300)
    +
    +	if indexer.Storage == nil {
    +		indexer.Storage = &datadoghqv1alpha1.DatadogBYOCClusterStorageSpec{
    +			VolumeClaimTemplate: &datadoghqv1alpha1.DatadogBYOCClusterEmbeddedPersistentVolumeClaim{},
    +		}
    +	}
    +	if indexer.Storage.VolumeClaimTemplate == nil {
    +		return
    +	}
    +
    +	claimSpec := &indexer.Storage.VolumeClaimTemplate.Spec
    +	if claimSpec.AccessModes == nil {
    +		claimSpec.AccessModes = []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce}
    +	}
    +	if claimSpec.Resources.Requests == nil {
    +		claimSpec.Resources.Requests = corev1.ResourceList{}
    +	}
    +	if _, found := claimSpec.Resources.Requests[corev1.ResourceStorage]; !found {
    +		claimSpec.Resources.Requests[corev1.ResourceStorage] = resource.MustParse("30Gi")
    +	}
    +}
    +
    +func applySearcherDefaults(searcher *datadoghqv1alpha1.DatadogBYOCClusterStatefulComponentSpec) {
    +	applyComponentDefaults(&searcher.DatadogBYOCClusterComponentSpec, 2, statefulResources())
    +	applyAutoscalingDefaults(searcher.Autoscaling, 50, 60, 300)
    +	if searcher.Storage == nil {
    +		searcher.Storage = &datadoghqv1alpha1.DatadogBYOCClusterStorageSpec{
    +			EmptyDir: &corev1.EmptyDirVolumeSource{},
    +		}
    +	}
    +}
    +
    +func applyMetastoreDefaults(metastore *datadoghqv1alpha1.DatadogBYOCClusterMetastoreComponentSpec) {
    +	applyComponentDefaults(&metastore.DatadogBYOCClusterComponentSpec, 2, deploymentResources())
    +}
    +
    +func applyCompactorDefaults(compactor *datadoghqv1alpha1.DatadogBYOCClusterComponentSpec) {
    +	applyComponentDefaults(compactor, 1, nil)
    +	if compactor.TerminationGracePeriodSeconds == nil {
    +		compactor.TerminationGracePeriodSeconds = ptr.To[int64](60)
    +	}
    +}
    +
    +func applyComponentDefaults(component *datadoghqv1alpha1.DatadogBYOCClusterComponentSpec, replicas int32, resources *corev1.ResourceRequirements) {
    +	if component.Replicas == nil {
    +		component.Replicas = new(replicas)

    Thanks! The replicas are ignored when building the actual STS if HPA is set in a later step 🙏

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on Oct 06, 2026 08:20 UTC
    Reviewer

    💡 Codex Review

    Here are some automated review suggestions for this pull request.

    Reviewed commit: b5dcb67912

    <details> <summary>ℹ️ About Codex in GitHub</summary>
    <br/>

    Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review

  • Mark a draft as ready

  • Comment "@codex review".
  • If Codex has suggestions, it will comment; otherwise it will react with 👍.

    Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

    </details>

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on code on Oct 06, 2026 08:20 UTC
    Code Review
    internal/controller/datadogbyoccluster/validation/validation.go:1
    @@ -0,0 +1,151 @@
    +// Unless explicitly stated otherwise all files in this repository are licensed
    +// under the Apache License Version 2.0.
    +// This product includes software developed at Datadog (https://www.datadoghq.com/).
    +// Copyright 2016-present Datadog, Inc.
    +
    +// Package validation enforces BYOC cross-field rules at reconciliation time.
    +// CEL/XValidation requires Kubernetes 1.25+, but the Operator's minimum supported
    +// Kubernetes version is not being raised. OperatorHub/Red Hat installations install
    +// all CRDs in the OLM bundle; they cannot omit the BYOC CRD on older clusters.
    +// Keep these rules in the reconciler so BYOC does not impose a newer Kubernetes
    +// requirement on every Operator installation.
    +// See https://github.com/DataDog/datadog-operator/pull/3501#discussion_r4080491818.
    +package validation
    +
    +import (
    +	"fmt"
    +
    +	corev1 "k8s.io/api/core/v1"
    +	"k8s.io/apimachinery/pkg/util/validation/field"
    +
    +	datadoghqv1alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1"
    +)
    +
    +// ValidateClusterSpec checks the cross-field rules after defaults and before image resolution.
    +// Validating the defaulted spec catches conflicts between explicit and default values.
    +// Required fields and single-field constraints are enforced by the CRD schema.
    +func ValidateClusterSpec(spec *datadoghqv1alpha1.DatadogBYOCClusterSpec) field.ErrorList {
    +	path := field.NewPath("spec")
    +	var errs field.ErrorList
    +	if spec.Release == nil && spec.ImageOverrides == nil {
    +		errs = append(errs, field.Required(path, "release or imageOverrides must be specified"))
    +	}
    +	if release := spec.Release; release != nil && (release.Tag == nil) == (release.Digest == nil) {
    +		errs = append(errs, field.Invalid(path.Child("release"), nil, "exactly one of tag or digest must be specified"))
    +	}
    +	if overrides := spec.ImageOverrides; overrides != nil {
    +		// Without a release, neither image can inherit a repository or version.
    +		requireComplete := spec.Release == nil
    +		errs = append(errs, validateImageOverride(overrides.BYOC, requireComplete, path.Child("imageOverrides", "byoc"))...)
    +		errs = append(errs, validateImageOverride(overrides.ObservabilityPipelinesWorker, requireComplete, path.Child("imageOverrides", "observabilityPipelinesWorker"))...)
    +	}
    +	if spec.Provider == nil || spec.Provider.AWS == nil {
    +		errs = append(errs, field.Required(path.Child("provider", "aws"), "at least one provider must be specified"))
    +	}
    +	// Validate the global setting even if every component overrides it.
    +	errs = append(errs, validatePodDisruptionBudget(spec.Global.PodDisruptionBudget, path.Child("global", "podDisruptionBudget"))...)
    +	if components := spec.Components; components != nil {
    +		componentPath := path.Child("components")
    +		errs = append(errs, validateQuickwitStatefulComponent(components.Indexer, componentPath.Child("indexer"))...)
    +		errs = append(errs, validateQuickwitStatefulComponent(components.Searcher, componentPath.Child("searcher"))...)
    +		for i := range components.Pipelines {
    +			errs = append(errs, ValidateStatefulComponent(&components.Pipelines[i].DatadogBYOCClusterStatefulComponentSpec, componentPath.Child("pipelines").Index(i))...)
    +		}
    +		if components.Metastore != nil {
    +			errs = append(errs, validateComponent(&components.Metastore.DatadogBYOCClusterComponentSpec, componentPath.Child("metastore"))...)
    +		}
    +		if components.ReadOnlyMetastore != nil {
    +			errs = append(errs, validateComponent(&components.ReadOnlyMetastore.DatadogBYOCClusterComponentSpec, componentPath.Child("readOnlyMetastore"))...)
    +		}
    +		errs = append(errs, validateComponent(components.ControlPlane, componentPath.Child("controlPlane"))...)
    +		errs = append(errs, validateComponent(components.Compactor, componentPath.Child("compactor"))...)
    +		errs = append(errs, validateComponent(components.Janitor, componentPath.Child("janitor"))...)
    +	}
    +	return errs
    +}
    +
    +func validateImageOverride(image *datadoghqv1alpha1.DatadogBYOCImageSpec, requireComplete bool, path *field.Path) field.ErrorList {
    +	if image == nil {
    +		if requireComplete {
    +			return field.ErrorList{field.Required(path, "image must be fully specified when release is omitted")}
    +		}
    +		return nil
    +	}
    +	var errs field.ErrorList
    +	if image.Tag != nil && image.Digest != nil {
    +		errs = append(errs, field.Forbidden(path, "tag and digest are mutually exclusive"))
    +	}
    +	if requireComplete {
    +		if image.Repository == nil || *image.Repository == "" {
    +			errs = append(errs, field.Required(path.Child("repository"), "repository must be non-empty when release is omitted"))
    +		}
    +		if image.Tag == nil && image.Digest == nil {
    +			errs = append(errs, field.Required(path, "tag or digest must be specified when release is omitted"))
    +		}
    +		if image.Tag != nil && *image.Tag == "" {
    +			errs = append(errs, field.Required(path.Child("tag"), "tag must be non-empty when release is omitted"))
    +		}
    +		if image.Digest != nil && *image.Digest == "" {
    +			errs = append(errs, field.Required(path.Child("digest"), "digest must be non-empty when release is omitted"))

    <sub><sub>!P2 Badge</sub></sub> Validate digest syntax for user-supplied images

    When a complete override supplies a nonempty malformed digest such as digest: nope, this validator accepts it, requiresResolution treats the image as complete, and image resolution produces an unusable repository@nope reference; the standalone Worker validator has the same gap. Despite the earlier thread's claimed schema fix, the fresh evidence in the reviewed tree is that both generated CRDs still define digest as an unconstrained string, so validate it as a SHA-256 digest here (and for Worker images), similarly to validateDigest in the resolver.

    Useful? React with 👍 / 👎.

    shuheiktgw shuheiktgw commented on code on Oct 06, 2026 08:22 UTC
    Code Review
    api/datadoghq/v1alpha1/datadogbyoccluster_types.go:1
    @@ -261,10 +261,12 @@ type DatadogBYOCClusterComponentsSpec struct {
     	ReadOnlyMetastore *DatadogBYOCClusterMetastoreComponentSpec `json:"readOnlyMetastore,omitempty"`
     
     	// Indexer configures the Indexer workload.
    +	// When Resources is specified, its memory limit is required for Quickwit node configuration sizing.
    shuheiktgw shuheiktgw commented on code on Oct 06, 2026 08:22 UTC
    Code Review
    api/datadoghq/v1alpha1/datadogbyoccluster_types.go:1
    @@ -261,10 +261,12 @@ type DatadogBYOCClusterComponentsSpec struct {
     	ReadOnlyMetastore *DatadogBYOCClusterMetastoreComponentSpec `json:"readOnlyMetastore,omitempty"`
     
     	// Indexer configures the Indexer workload.
    +	// When Resources is specified, its memory limit is required for Quickwit node configuration sizing.
     	// +kubebuilder:validation:Required
     	Indexer *DatadogBYOCClusterStatefulComponentSpec `json:"indexer,omitempty"`
     
     	// Searcher configures the Searcher workload.
    +	// When Resources is specified, its memory limit is required for Quickwit node configuration sizing.
    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on code on Oct 06, 2026 08:24 UTC
    Code Review
    internal/controller/datadogbyoccluster/validation/validation.go:1
    @@ -0,0 +1,151 @@
    +// Unless explicitly stated otherwise all files in this repository are licensed
    +// under the Apache License Version 2.0.
    +// This product includes software developed at Datadog (https://www.datadoghq.com/).
    +// Copyright 2016-present Datadog, Inc.
    +
    +// Package validation enforces BYOC cross-field rules at reconciliation time.
    +// CEL/XValidation requires Kubernetes 1.25+, but the Operator's minimum supported
    +// Kubernetes version is not being raised. OperatorHub/Red Hat installations install
    +// all CRDs in the OLM bundle; they cannot omit the BYOC CRD on older clusters.
    +// Keep these rules in the reconciler so BYOC does not impose a newer Kubernetes
    +// requirement on every Operator installation.
    +// See https://github.com/DataDog/datadog-operator/pull/3501#discussion_r4080491818.
    +package validation
    +
    +import (
    +	"fmt"
    +
    +	corev1 "k8s.io/api/core/v1"
    +	"k8s.io/apimachinery/pkg/util/validation/field"
    +
    +	datadoghqv1alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1"
    +)
    +
    +// ValidateClusterSpec checks the cross-field rules after defaults and before image resolution.
    +// Validating the defaulted spec catches conflicts between explicit and default values.
    +// Required fields and single-field constraints are enforced by the CRD schema.
    +func ValidateClusterSpec(spec *datadoghqv1alpha1.DatadogBYOCClusterSpec) field.ErrorList {
    +	path := field.NewPath("spec")
    +	var errs field.ErrorList
    +	if spec.Release == nil && spec.ImageOverrides == nil {
    +		errs = append(errs, field.Required(path, "release or imageOverrides must be specified"))
    +	}
    +	if release := spec.Release; release != nil && (release.Tag == nil) == (release.Digest == nil) {
    +		errs = append(errs, field.Invalid(path.Child("release"), nil, "exactly one of tag or digest must be specified"))
    +	}
    +	if overrides := spec.ImageOverrides; overrides != nil {
    +		// Without a release, neither image can inherit a repository or version.
    +		requireComplete := spec.Release == nil
    +		errs = append(errs, validateImageOverride(overrides.BYOC, requireComplete, path.Child("imageOverrides", "byoc"))...)
    +		errs = append(errs, validateImageOverride(overrides.ObservabilityPipelinesWorker, requireComplete, path.Child("imageOverrides", "observabilityPipelinesWorker"))...)
    +	}
    +	if spec.Provider == nil || spec.Provider.AWS == nil {
    +		errs = append(errs, field.Required(path.Child("provider", "aws"), "at least one provider must be specified"))
    +	}
    +	// Validate the global setting even if every component overrides it.
    +	errs = append(errs, validatePodDisruptionBudget(spec.Global.PodDisruptionBudget, path.Child("global", "podDisruptionBudget"))...)
    +	if components := spec.Components; components != nil {
    +		componentPath := path.Child("components")
    +		errs = append(errs, validateQuickwitStatefulComponent(components.Indexer, componentPath.Child("indexer"))...)
    +		errs = append(errs, validateQuickwitStatefulComponent(components.Searcher, componentPath.Child("searcher"))...)
    +		for i := range components.Pipelines {
    +			errs = append(errs, ValidateStatefulComponent(&components.Pipelines[i].DatadogBYOCClusterStatefulComponentSpec, componentPath.Child("pipelines").Index(i))...)
    +		}
    +		if components.Metastore != nil {
    +			errs = append(errs, validateComponent(&components.Metastore.DatadogBYOCClusterComponentSpec, componentPath.Child("metastore"))...)
    +		}
    +		if components.ReadOnlyMetastore != nil {
    +			errs = append(errs, validateComponent(&components.ReadOnlyMetastore.DatadogBYOCClusterComponentSpec, componentPath.Child("readOnlyMetastore"))...)
    +		}
    +		errs = append(errs, validateComponent(components.ControlPlane, componentPath.Child("controlPlane"))...)
    +		errs = append(errs, validateComponent(components.Compactor, componentPath.Child("compactor"))...)
    +		errs = append(errs, validateComponent(components.Janitor, componentPath.Child("janitor"))...)
    +	}
    +	return errs
    +}
    +
    +func validateImageOverride(image *datadoghqv1alpha1.DatadogBYOCImageSpec, requireComplete bool, path *field.Path) field.ErrorList {
    +	if image == nil {
    +		if requireComplete {
    +			return field.ErrorList{field.Required(path, "image must be fully specified when release is omitted")}
    +		}
    +		return nil
    +	}
    +	var errs field.ErrorList
    +	if image.Tag != nil && image.Digest != nil {
    +		errs = append(errs, field.Forbidden(path, "tag and digest are mutually exclusive"))
    +	}
    +	if requireComplete {
    +		if image.Repository == nil || *image.Repository == "" {
    +			errs = append(errs, field.Required(path.Child("repository"), "repository must be non-empty when release is omitted"))
    +		}
    +		if image.Tag == nil && image.Digest == nil {
    +			errs = append(errs, field.Required(path, "tag or digest must be specified when release is omitted"))
    +		}
    +		if image.Tag != nil && *image.Tag == "" {
    +			errs = append(errs, field.Required(path.Child("tag"), "tag must be non-empty when release is omitted"))
    +		}
    +		if image.Digest != nil && *image.Digest == "" {
    +			errs = append(errs, field.Required(path.Child("digest"), "digest must be non-empty when release is omitted"))
    +		}
    +	}
    +	return errs
    +}
    +
    +// ValidateStatefulComponent is shared by BYOC components and standalone Workers.
    +func ValidateStatefulComponent(component *datadoghqv1alpha1.DatadogBYOCClusterStatefulComponentSpec, path *field.Path) field.ErrorList {
    +	if component == nil {
    +		return nil
    +	}
    +	errs := validateComponent(&component.DatadogBYOCClusterComponentSpec, path)
    +	errs = append(errs, validateAutoscaling(component.Autoscaling, path.Child("autoscaling"))...)
    +	if storage := component.Storage; storage != nil && (storage.EmptyDir == nil) == (storage.VolumeClaimTemplate == nil) {
    +		errs = append(errs, field.Invalid(path.Child("storage"), nil, "exactly one storage type must be specified"))
    +	}
    +	return errs
    +}
    +
    +// validateQuickwitStatefulComponent also requires the memory limit used to size the Quickwit node configuration.
    +func validateQuickwitStatefulComponent(component *datadoghqv1alpha1.DatadogBYOCClusterStatefulComponentSpec, path *field.Path) field.ErrorList {
    +	if component == nil {
    +		return nil
    +	}
    +	errs := ValidateStatefulComponent(component, path)
    +	if component.Resources != nil {
    +		if _, ok := component.Resources.Limits[corev1.ResourceMemory]; !ok {
    +			errs = append(errs, field.Required(path.Child("resources", "limits", "memory"), "resources.limits.memory must be specified when resources is set"))
    +		}
    +	}
    +	return errs
    +}
    +
    +func validateAutoscaling(autoscaling *datadoghqv1alpha1.DatadogBYOCClusterAutoscalingSpec, path *field.Path) field.ErrorList {
    +	if autoscaling == nil {
    +		return nil
    +	}
    +	var errs field.ErrorList
    +	if autoscaling.MinReplicas != nil && *autoscaling.MinReplicas < 1 {
    +		errs = append(errs, field.Invalid(path.Child("minReplicas"), *autoscaling.MinReplicas, "must be greater than or equal to 1"))
    +	}
    +	if autoscaling.MaxReplicas != nil && *autoscaling.MaxReplicas < 1 {
    +		errs = append(errs, field.Invalid(path.Child("maxReplicas"), *autoscaling.MaxReplicas, "must be greater than or equal to 1"))
    +	}
    +	if autoscaling.MinReplicas != nil && autoscaling.MaxReplicas != nil && *autoscaling.MinReplicas > *autoscaling.MaxReplicas {
    +		errs = append(errs, field.Invalid(path.Child("maxReplicas"), *autoscaling.MaxReplicas, fmt.Sprintf("must be greater than or equal to minReplicas (%d)", *autoscaling.MinReplicas)))
    +	}
    +	return errs

    <sub><sub>!P2 Badge</sub></sub> Validate autoscaling metric/source combinations

    When a nonempty metric such as metrics: [{type: Resource}] is supplied, defaulting preserves it and this validator checks only replica bounds. The generated CRD requires type but does not require the corresponding source or prevent multiple source objects, so the parent resource is admitted while the resulting HorizontalPodAutoscaler is rejected; validate that each metric has exactly the source matching its type (and a valid target) for both BYOC and standalone Workers.

    Useful? React with 👍 / 👎.

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on Oct 06, 2026 08:24 UTC
    Reviewer

    💡 Codex Review

    Here are some automated review suggestions for this pull request.

    Reviewed commit: 5810fb0ddf

    <details> <summary>ℹ️ About Codex in GitHub</summary>
    <br/>

    Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review

  • Mark a draft as ready

  • Comment "@codex review".
  • If Codex has suggestions, it will comment; otherwise it will react with 👍.

    Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

    </details>

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on code on Oct 06, 2026 08:24 UTC
    Code Review
    internal/controller/datadogbyoccluster/defaults/defaults.go:1
    @@ -0,0 +1,191 @@
    +// Unless explicitly stated otherwise all files in this repository are licensed
    +// under the Apache License Version 2.0.
    +// This product includes software developed by Datadog (https://www.datadoghq.com/).
    +// Copyright 2016-present Datadog, Inc.
    +
    +package defaults
    +
    +import (
    +	autoscalingv2 "k8s.io/api/autoscaling/v2"
    +	corev1 "k8s.io/api/core/v1"
    +	"k8s.io/apimachinery/pkg/api/resource"
    +	"k8s.io/utils/ptr"
    +
    +	datadoghqv1alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1"
    +)
    +
    +// Apply returns a deep copy of the cluster with reconciliation-time defaults applied.
    +// DatadogBYOCCluster does not use a mutating admission webhook, so defaults that cannot be
    +// expressed in the shared CRD schema are applied here instead.
    +func Apply(cluster *datadoghqv1alpha1.DatadogBYOCCluster) *datadoghqv1alpha1.DatadogBYOCCluster {
    +	defaulted := cluster.DeepCopy()
    +	components := defaulted.Spec.Components
    +	applyIndexerDefaults(components.Indexer)
    +	applySearcherDefaults(components.Searcher)
    +	for i := range components.Pipelines {
    +		applyPipelineDefaults(&components.Pipelines[i].DatadogBYOCClusterPipelineComponentSpec)
    +	}
    +	applyMetastoreDefaults(components.Metastore)
    +	applyComponentDefaults(components.ControlPlane, 1, deploymentResources())
    +	applyComponentDefaults(components.Janitor, 1, deploymentResources())
    +	if components.ReadOnlyMetastore != nil {
    +		applyMetastoreDefaults(components.ReadOnlyMetastore)
    +	}
    +	if components.Compactor != nil {
    +		applyCompactorDefaults(components.Compactor)
    +	}
    +	return defaulted
    +}
    +
    +func applyPipelineDefaults(pipeline *datadoghqv1alpha1.DatadogBYOCClusterPipelineComponentSpec) {
    +	applyComponentDefaults(&pipeline.DatadogBYOCClusterComponentSpec, 2, pipelineResources())
    +	if pipeline.TerminationGracePeriodSeconds == nil {
    +		pipeline.TerminationGracePeriodSeconds = ptr.To[int64](70)
    +	}
    +	applyAutoscalingDefaults(pipeline.Autoscaling, 70, 0, 300)
    +
    +	if pipeline.Storage == nil {
    +		pipeline.Storage = &datadoghqv1alpha1.DatadogBYOCClusterStorageSpec{
    +			VolumeClaimTemplate: &datadoghqv1alpha1.DatadogBYOCClusterEmbeddedPersistentVolumeClaim{},
    +		}
    +	}
    +	if pipeline.Storage.VolumeClaimTemplate == nil {
    +		return
    +	}
    +
    +	claimSpec := &pipeline.Storage.VolumeClaimTemplate.Spec
    +	if claimSpec.AccessModes == nil {
    +		claimSpec.AccessModes = []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce}
    +	}
    +	if claimSpec.Resources.Requests == nil {
    +		claimSpec.Resources.Requests = corev1.ResourceList{}
    +	}
    +	if _, found := claimSpec.Resources.Requests[corev1.ResourceStorage]; !found {
    +		claimSpec.Resources.Requests[corev1.ResourceStorage] = resource.MustParse("30Gi")
    +	}
    +}
    +
    +func applyIndexerDefaults(indexer *datadoghqv1alpha1.DatadogBYOCClusterStatefulComponentSpec) {
    +	applyComponentDefaults(&indexer.DatadogBYOCClusterComponentSpec, 2, statefulResources())
    +	if indexer.TerminationGracePeriodSeconds == nil {
    +		indexer.TerminationGracePeriodSeconds = ptr.To[int64](300)
    +	}
    +	applyAutoscalingDefaults(indexer.Autoscaling, 70, 0, 300)
    +
    +	if indexer.Storage == nil {
    +		indexer.Storage = &datadoghqv1alpha1.DatadogBYOCClusterStorageSpec{
    +			VolumeClaimTemplate: &datadoghqv1alpha1.DatadogBYOCClusterEmbeddedPersistentVolumeClaim{},
    +		}
    +	}
    +	if indexer.Storage.VolumeClaimTemplate == nil {
    +		return
    +	}
    +
    +	claimSpec := &indexer.Storage.VolumeClaimTemplate.Spec
    +	if claimSpec.AccessModes == nil {
    +		claimSpec.AccessModes = []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce}
    +	}
    +	if claimSpec.Resources.Requests == nil {
    +		claimSpec.Resources.Requests = corev1.ResourceList{}
    +	}
    +	if _, found := claimSpec.Resources.Requests[corev1.ResourceStorage]; !found {
    +		claimSpec.Resources.Requests[corev1.ResourceStorage] = resource.MustParse("30Gi")
    +	}
    +}
    +
    +func applySearcherDefaults(searcher *datadoghqv1alpha1.DatadogBYOCClusterStatefulComponentSpec) {
    +	applyComponentDefaults(&searcher.DatadogBYOCClusterComponentSpec, 2, statefulResources())
    +	applyAutoscalingDefaults(searcher.Autoscaling, 50, 60, 300)
    +	if searcher.Storage == nil {
    +		searcher.Storage = &datadoghqv1alpha1.DatadogBYOCClusterStorageSpec{
    +			EmptyDir: &corev1.EmptyDirVolumeSource{},
    +		}
    +	}

    <sub><sub>!P2 Badge</sub></sub> Complete explicitly selected Searcher PVC templates

    When a Searcher selects storage.volumeClaimTemplate: {}, Storage is non-nil so this branch leaves the claim empty, unlike the Indexer and pipeline paths that add ReadWriteOnce and a storage request. The shared validator accepts it because exactly one storage type is selected, but Kubernetes rejects the generated PVC for lacking access modes and requested capacity; default the selected template's required fields or reject an incomplete claim.

    Useful? React with 👍 / 👎.

    shuheiktgw shuheiktgw commented on code on Oct 06, 2026 08:28 UTC
    Code Review
    internal/controller/datadogbyoccluster/defaults/defaults.go:1
    @@ -0,0 +1,191 @@
    +// Unless explicitly stated otherwise all files in this repository are licensed
    +// under the Apache License Version 2.0.
    +// This product includes software developed by Datadog (https://www.datadoghq.com/).
    +// Copyright 2016-present Datadog, Inc.
    +
    +package defaults
    +
    +import (
    +	autoscalingv2 "k8s.io/api/autoscaling/v2"
    +	corev1 "k8s.io/api/core/v1"
    +	"k8s.io/apimachinery/pkg/api/resource"
    +	"k8s.io/utils/ptr"
    +
    +	datadoghqv1alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1"
    +)
    +
    +// Apply returns a deep copy of the cluster with reconciliation-time defaults applied.
    +// DatadogBYOCCluster does not use a mutating admission webhook, so defaults that cannot be
    +// expressed in the shared CRD schema are applied here instead.
    +func Apply(cluster *datadoghqv1alpha1.DatadogBYOCCluster) *datadoghqv1alpha1.DatadogBYOCCluster {
    +	defaulted := cluster.DeepCopy()
    +	components := defaulted.Spec.Components
    +	applyIndexerDefaults(components.Indexer)
    +	applySearcherDefaults(components.Searcher)
    +	for i := range components.Pipelines {
    +		applyPipelineDefaults(&components.Pipelines[i].DatadogBYOCClusterPipelineComponentSpec)
    +	}
    +	applyMetastoreDefaults(components.Metastore)
    +	applyComponentDefaults(components.ControlPlane, 1, deploymentResources())
    +	applyComponentDefaults(components.Janitor, 1, deploymentResources())
    +	if components.ReadOnlyMetastore != nil {
    +		applyMetastoreDefaults(components.ReadOnlyMetastore)
    +	}
    +	if components.Compactor != nil {
    +		applyCompactorDefaults(components.Compactor)
    +	}
    +	return defaulted
    +}
    +
    +func applyPipelineDefaults(pipeline *datadoghqv1alpha1.DatadogBYOCClusterPipelineComponentSpec) {
    +	applyComponentDefaults(&pipeline.DatadogBYOCClusterComponentSpec, 2, pipelineResources())
    +	if pipeline.TerminationGracePeriodSeconds == nil {
    +		pipeline.TerminationGracePeriodSeconds = ptr.To[int64](70)
    +	}
    +	applyAutoscalingDefaults(pipeline.Autoscaling, 70, 0, 300)
    +
    +	if pipeline.Storage == nil {
    +		pipeline.Storage = &datadoghqv1alpha1.DatadogBYOCClusterStorageSpec{
    +			VolumeClaimTemplate: &datadoghqv1alpha1.DatadogBYOCClusterEmbeddedPersistentVolumeClaim{},
    +		}
    +	}
    +	if pipeline.Storage.VolumeClaimTemplate == nil {
    +		return
    +	}
    +
    +	claimSpec := &pipeline.Storage.VolumeClaimTemplate.Spec
    +	if claimSpec.AccessModes == nil {
    +		claimSpec.AccessModes = []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce}
    +	}
    +	if claimSpec.Resources.Requests == nil {
    +		claimSpec.Resources.Requests = corev1.ResourceList{}
    +	}
    +	if _, found := claimSpec.Resources.Requests[corev1.ResourceStorage]; !found {
    +		claimSpec.Resources.Requests[corev1.ResourceStorage] = resource.MustParse("30Gi")
    +	}
    +}
    +
    +func applyIndexerDefaults(indexer *datadoghqv1alpha1.DatadogBYOCClusterStatefulComponentSpec) {
    +	applyComponentDefaults(&indexer.DatadogBYOCClusterComponentSpec, 2, statefulResources())
    +	if indexer.TerminationGracePeriodSeconds == nil {
    +		indexer.TerminationGracePeriodSeconds = ptr.To[int64](300)

    Moved all default values into a grouped const block at the top of the file (also applied to the Worker defaults) in 2af8d410.

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on code on Oct 06, 2026 08:31 UTC
    Code Review
    internal/controller/datadogbyoccluster/validation/validation.go:1
    @@ -0,0 +1,151 @@
    +// Unless explicitly stated otherwise all files in this repository are licensed
    +// under the Apache License Version 2.0.
    +// This product includes software developed at Datadog (https://www.datadoghq.com/).
    +// Copyright 2016-present Datadog, Inc.
    +
    +// Package validation enforces BYOC cross-field rules at reconciliation time.
    +// CEL/XValidation requires Kubernetes 1.25+, but the Operator's minimum supported
    +// Kubernetes version is not being raised. OperatorHub/Red Hat installations install
    +// all CRDs in the OLM bundle; they cannot omit the BYOC CRD on older clusters.
    +// Keep these rules in the reconciler so BYOC does not impose a newer Kubernetes
    +// requirement on every Operator installation.
    +// See https://github.com/DataDog/datadog-operator/pull/3501#discussion_r4080491818.
    +package validation
    +
    +import (
    +	"fmt"
    +
    +	corev1 "k8s.io/api/core/v1"
    +	"k8s.io/apimachinery/pkg/util/validation/field"
    +
    +	datadoghqv1alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1"
    +)
    +
    +// ValidateClusterSpec checks the cross-field rules after defaults and before image resolution.
    +// Validating the defaulted spec catches conflicts between explicit and default values.
    +// Required fields and single-field constraints are enforced by the CRD schema.
    +func ValidateClusterSpec(spec *datadoghqv1alpha1.DatadogBYOCClusterSpec) field.ErrorList {
    +	path := field.NewPath("spec")
    +	var errs field.ErrorList
    +	if spec.Release == nil && spec.ImageOverrides == nil {
    +		errs = append(errs, field.Required(path, "release or imageOverrides must be specified"))
    +	}
    +	if release := spec.Release; release != nil && (release.Tag == nil) == (release.Digest == nil) {
    +		errs = append(errs, field.Invalid(path.Child("release"), nil, "exactly one of tag or digest must be specified"))
    +	}
    +	if overrides := spec.ImageOverrides; overrides != nil {
    +		// Without a release, neither image can inherit a repository or version.
    +		requireComplete := spec.Release == nil
    +		errs = append(errs, validateImageOverride(overrides.BYOC, requireComplete, path.Child("imageOverrides", "byoc"))...)
    +		errs = append(errs, validateImageOverride(overrides.ObservabilityPipelinesWorker, requireComplete, path.Child("imageOverrides", "observabilityPipelinesWorker"))...)
    +	}
    +	if spec.Provider == nil || spec.Provider.AWS == nil {
    +		errs = append(errs, field.Required(path.Child("provider", "aws"), "at least one provider must be specified"))
    +	}
    +	// Validate the global setting even if every component overrides it.
    +	errs = append(errs, validatePodDisruptionBudget(spec.Global.PodDisruptionBudget, path.Child("global", "podDisruptionBudget"))...)
    +	if components := spec.Components; components != nil {
    +		componentPath := path.Child("components")
    +		errs = append(errs, validateQuickwitStatefulComponent(components.Indexer, componentPath.Child("indexer"))...)
    +		errs = append(errs, validateQuickwitStatefulComponent(components.Searcher, componentPath.Child("searcher"))...)
    +		for i := range components.Pipelines {
    +			errs = append(errs, ValidateStatefulComponent(&components.Pipelines[i].DatadogBYOCClusterStatefulComponentSpec, componentPath.Child("pipelines").Index(i))...)
    +		}
    +		if components.Metastore != nil {
    +			errs = append(errs, validateComponent(&components.Metastore.DatadogBYOCClusterComponentSpec, componentPath.Child("metastore"))...)
    +		}
    +		if components.ReadOnlyMetastore != nil {
    +			errs = append(errs, validateComponent(&components.ReadOnlyMetastore.DatadogBYOCClusterComponentSpec, componentPath.Child("readOnlyMetastore"))...)
    +		}
    +		errs = append(errs, validateComponent(components.ControlPlane, componentPath.Child("controlPlane"))...)
    +		errs = append(errs, validateComponent(components.Compactor, componentPath.Child("compactor"))...)
    +		errs = append(errs, validateComponent(components.Janitor, componentPath.Child("janitor"))...)
    +	}
    +	return errs
    +}
    +
    +func validateImageOverride(image *datadoghqv1alpha1.DatadogBYOCImageSpec, requireComplete bool, path *field.Path) field.ErrorList {
    +	if image == nil {
    +		if requireComplete {
    +			return field.ErrorList{field.Required(path, "image must be fully specified when release is omitted")}
    +		}
    +		return nil
    +	}
    +	var errs field.ErrorList
    +	if image.Tag != nil && image.Digest != nil {
    +		errs = append(errs, field.Forbidden(path, "tag and digest are mutually exclusive"))
    +	}
    +	if requireComplete {
    +		if image.Repository == nil || *image.Repository == "" {
    +			errs = append(errs, field.Required(path.Child("repository"), "repository must be non-empty when release is omitted"))
    +		}
    +		if image.Tag == nil && image.Digest == nil {
    +			errs = append(errs, field.Required(path, "tag or digest must be specified when release is omitted"))
    +		}
    +		if image.Tag != nil && *image.Tag == "" {
    +			errs = append(errs, field.Required(path.Child("tag"), "tag must be non-empty when release is omitted"))
    +		}
    +		if image.Digest != nil && *image.Digest == "" {
    +			errs = append(errs, field.Required(path.Child("digest"), "digest must be non-empty when release is omitted"))
    +		}
    +	}
    +	return errs
    +}
    +
    +// ValidateStatefulComponent is shared by BYOC components and standalone Workers.
    +func ValidateStatefulComponent(component *datadoghqv1alpha1.DatadogBYOCClusterStatefulComponentSpec, path *field.Path) field.ErrorList {
    +	if component == nil {
    +		return nil
    +	}
    +	errs := validateComponent(&component.DatadogBYOCClusterComponentSpec, path)
    +	errs = append(errs, validateAutoscaling(component.Autoscaling, path.Child("autoscaling"))...)
    +	if storage := component.Storage; storage != nil && (storage.EmptyDir == nil) == (storage.VolumeClaimTemplate == nil) {
    +		errs = append(errs, field.Invalid(path.Child("storage"), nil, "exactly one storage type must be specified"))
    +	}
    +	return errs
    +}
    +
    +// validateQuickwitStatefulComponent also requires the memory limit used to size the Quickwit node configuration.
    +func validateQuickwitStatefulComponent(component *datadoghqv1alpha1.DatadogBYOCClusterStatefulComponentSpec, path *field.Path) field.ErrorList {
    +	if component == nil {
    +		return nil
    +	}
    +	errs := ValidateStatefulComponent(component, path)
    +	if component.Resources != nil {
    +		if _, ok := component.Resources.Limits[corev1.ResourceMemory]; !ok {
    +			errs = append(errs, field.Required(path.Child("resources", "limits", "memory"), "resources.limits.memory must be specified when resources is set"))
    +		}
    +	}
    +	return errs
    +}
    +
    +func validateAutoscaling(autoscaling *datadoghqv1alpha1.DatadogBYOCClusterAutoscalingSpec, path *field.Path) field.ErrorList {
    +	if autoscaling == nil {
    +		return nil
    +	}
    +	var errs field.ErrorList
    +	if autoscaling.MinReplicas != nil && *autoscaling.MinReplicas < 1 {
    +		errs = append(errs, field.Invalid(path.Child("minReplicas"), *autoscaling.MinReplicas, "must be greater than or equal to 1"))
    +	}
    +	if autoscaling.MaxReplicas != nil && *autoscaling.MaxReplicas < 1 {
    +		errs = append(errs, field.Invalid(path.Child("maxReplicas"), *autoscaling.MaxReplicas, "must be greater than or equal to 1"))
    +	}
    +	if autoscaling.MinReplicas != nil && autoscaling.MaxReplicas != nil && *autoscaling.MinReplicas > *autoscaling.MaxReplicas {
    +		errs = append(errs, field.Invalid(path.Child("maxReplicas"), *autoscaling.MaxReplicas, fmt.Sprintf("must be greater than or equal to minReplicas (%d)", *autoscaling.MinReplicas)))
    +	}
    +	return errs
    +}
    +
    +func validateComponent(component *datadoghqv1alpha1.DatadogBYOCClusterComponentSpec, path *field.Path) field.ErrorList {
    +	if component == nil {
    +		return nil
    +	}
    +	return validatePodDisruptionBudget(component.PodDisruptionBudget, path.Child("podDisruptionBudget"))

    <sub><sub>!P2 Badge</sub></sub> Reject negative replica counts

    When autoscaling is omitted and a BYOC component or standalone Worker specifies replicas: -1, the generated CRDs admit it because the field has no minimum, defaulting preserves it, and this validator accepts it because it only checks the disruption budget. The resulting Deployment or StatefulSet is rejected by Kubernetes, so reject negative replica counts here or add a Minimum=0 schema constraint.

    Useful? React with 👍 / 👎.

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on Oct 06, 2026 08:31 UTC
    Reviewer

    💡 Codex Review

    Here are some automated review suggestions for this pull request.

    Reviewed commit: 2af8d41033

    <details> <summary>ℹ️ About Codex in GitHub</summary>
    <br/>

    Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review

  • Mark a draft as ready

  • Comment "@codex review".
  • If Codex has suggestions, it will comment; otherwise it will react with 👍.

    Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

    </details>

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on code on Oct 06, 2026 08:41 UTC
    Code Review
    internal/controller/datadogbyoccluster/validation/validation.go:1
    @@ -0,0 +1,151 @@
    +// Unless explicitly stated otherwise all files in this repository are licensed
    +// under the Apache License Version 2.0.
    +// This product includes software developed at Datadog (https://www.datadoghq.com/).
    +// Copyright 2016-present Datadog, Inc.
    +
    +// Package validation enforces BYOC cross-field rules at reconciliation time.
    +// CEL/XValidation requires Kubernetes 1.25+, but the Operator's minimum supported
    +// Kubernetes version is not being raised. OperatorHub/Red Hat installations install
    +// all CRDs in the OLM bundle; they cannot omit the BYOC CRD on older clusters.
    +// Keep these rules in the reconciler so BYOC does not impose a newer Kubernetes
    +// requirement on every Operator installation.
    +// See https://github.com/DataDog/datadog-operator/pull/3501#discussion_r4080491818.
    +package validation
    +
    +import (
    +	"fmt"
    +
    +	corev1 "k8s.io/api/core/v1"
    +	"k8s.io/apimachinery/pkg/util/validation/field"
    +
    +	datadoghqv1alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1"
    +)
    +
    +// ValidateClusterSpec checks the cross-field rules after defaults and before image resolution.
    +// Validating the defaulted spec catches conflicts between explicit and default values.
    +// Required fields and single-field constraints are enforced by the CRD schema.
    +func ValidateClusterSpec(spec *datadoghqv1alpha1.DatadogBYOCClusterSpec) field.ErrorList {
    +	path := field.NewPath("spec")
    +	var errs field.ErrorList
    +	if spec.Release == nil && spec.ImageOverrides == nil {
    +		errs = append(errs, field.Required(path, "release or imageOverrides must be specified"))
    +	}
    +	if release := spec.Release; release != nil && (release.Tag == nil) == (release.Digest == nil) {
    +		errs = append(errs, field.Invalid(path.Child("release"), nil, "exactly one of tag or digest must be specified"))
    +	}
    +	if overrides := spec.ImageOverrides; overrides != nil {
    +		// Without a release, neither image can inherit a repository or version.
    +		requireComplete := spec.Release == nil
    +		errs = append(errs, validateImageOverride(overrides.BYOC, requireComplete, path.Child("imageOverrides", "byoc"))...)
    +		errs = append(errs, validateImageOverride(overrides.ObservabilityPipelinesWorker, requireComplete, path.Child("imageOverrides", "observabilityPipelinesWorker"))...)
    +	}
    +	if spec.Provider == nil || spec.Provider.AWS == nil {
    +		errs = append(errs, field.Required(path.Child("provider", "aws"), "at least one provider must be specified"))
    +	}
    +	// Validate the global setting even if every component overrides it.
    +	errs = append(errs, validatePodDisruptionBudget(spec.Global.PodDisruptionBudget, path.Child("global", "podDisruptionBudget"))...)
    +	if components := spec.Components; components != nil {
    +		componentPath := path.Child("components")
    +		errs = append(errs, validateQuickwitStatefulComponent(components.Indexer, componentPath.Child("indexer"))...)
    +		errs = append(errs, validateQuickwitStatefulComponent(components.Searcher, componentPath.Child("searcher"))...)
    +		for i := range components.Pipelines {
    +			errs = append(errs, ValidateStatefulComponent(&components.Pipelines[i].DatadogBYOCClusterStatefulComponentSpec, componentPath.Child("pipelines").Index(i))...)
    +		}
    +		if components.Metastore != nil {
    +			errs = append(errs, validateComponent(&components.Metastore.DatadogBYOCClusterComponentSpec, componentPath.Child("metastore"))...)
    +		}
    +		if components.ReadOnlyMetastore != nil {
    +			errs = append(errs, validateComponent(&components.ReadOnlyMetastore.DatadogBYOCClusterComponentSpec, componentPath.Child("readOnlyMetastore"))...)
    +		}
    +		errs = append(errs, validateComponent(components.ControlPlane, componentPath.Child("controlPlane"))...)
    +		errs = append(errs, validateComponent(components.Compactor, componentPath.Child("compactor"))...)
    +		errs = append(errs, validateComponent(components.Janitor, componentPath.Child("janitor"))...)
    +	}
    +	return errs
    +}
    +
    +func validateImageOverride(image *datadoghqv1alpha1.DatadogBYOCImageSpec, requireComplete bool, path *field.Path) field.ErrorList {
    +	if image == nil {
    +		if requireComplete {
    +			return field.ErrorList{field.Required(path, "image must be fully specified when release is omitted")}
    +		}
    +		return nil
    +	}
    +	var errs field.ErrorList
    +	if image.Tag != nil && image.Digest != nil {
    +		errs = append(errs, field.Forbidden(path, "tag and digest are mutually exclusive"))

    <sub><sub>!P2 Badge</sub></sub> Validate override repository and tag syntax

    When a complete override uses a nonempty but invalid value such as repository: "registry.example.com/UPPER" or tag: "bad/tag", this validator accepts it and requiresResolution considers the image complete. The resolver then copies these strings verbatim into the resulting image reference, so the managed Pod is rejected rather than the parent resource receiving an InvalidConfiguration error. Apply the same repository/tag parsing used by validateReleaseImage to user-supplied overrides (and to standalone Worker images).

    Useful? React with 👍 / 👎.

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on Oct 06, 2026 08:41 UTC
    Reviewer

    💡 Codex Review

    Here are some automated review suggestions for this pull request.

    Reviewed commit: 98e9c6bd25

    <details> <summary>ℹ️ About Codex in GitHub</summary>
    <br/>

    Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review

  • Mark a draft as ready

  • Comment "@codex review".
  • If Codex has suggestions, it will comment; otherwise it will react with 👍.

    Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

    </details>

    Reviewers
    Assignees
    shuheiktgw shuheiktgw
    Labels
    risk: low confidence: 88.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 57.6% (MEDIUM) · Higher = larger blast radius
    57.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 88.8% · Lower = rushed or shallow review
    88.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 6.5% · Safe to merge
    6.5%