Skip to content

Conversation

@patrykw-splunk
Copy link
Collaborator

@patrykw-splunk patrykw-splunk commented Feb 2, 2026

Description

Implements an opt-in validation webhook for Splunk Enterprise CRDs that validates spec fields on CREATE and UPDATE operations, providing immediate feedback when invalid configurations are submitted.

The webhook is disabled by default and can be enabled by setting ENABLE_WEBHOOKS=true or using the config/default-with-webhook kustomize overlay.

Key Changes

New Validation Package (pkg/splunk/enterprise/validation/)

  • Validator framework - Generic type-safe validator using Go generics
  • Webhook server - HTTP server with TLS support on port 9443
  • CRD validators - Standalone, IndexerCluster, SearchHeadCluster, ClusterManager, LicenseManager, MonitoringConsole

Validated Fields

Field Rule
spec.replicas ≥ 0 (Standalone), ≥ 3 (IndexerCluster, SearchHeadCluster)
spec.imagePullPolicy Must be Always, Never, or IfNotPresent
spec.livenessInitialDelaySeconds ≥ 3
spec.readinessInitialDelaySeconds ≥ 3
spec.etcVolumeStorageConfig.storageCapacity Format ^[0-9]+Gi$
spec.varVolumeStorageConfig.storageCapacity Format ^[0-9]+Gi$
spec.smartstore Volume/index name validation (conditional)
spec.appRepo App source name/location validation (conditional)

Webhook Infrastructure

  • config/webhook/ - Service and ValidatingWebhookConfiguration
  • config/certmanager/ - TLS certificate via cert-manager
  • config/default-with-webhook/ - Opt-in kustomize overlay

Documentation

  • docs/ValidationWebhook.md

Testing and Verification

Comprehensive unit tests (~95% coverage)
Server and HTTP handler tests

Related Issues

N/A

PR Checklist

  • Code changes adhere to the project's coding standards.
  • Relevant unit and integration tests are included.
  • Documentation has been updated accordingly.
  • All tests pass locally.
  • The PR description follows the project's guidelines.

patrykw-splunk and others added 4 commits February 2, 2026 16:24
* implementation of dummy validation webhook

---------

Co-authored-by: Patryk Wasielewski <pwasiele@splunk.com>
Implement Validation Webhook logic + unit tests + mux server for webhook

---------

Co-authored-by: Patryk Wasielewski <pwasiele@splunk.com>
@github-actions
Copy link
Contributor

github-actions bot commented Feb 2, 2026

CLA Assistant Lite bot:
Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


0 out of 2 committers have signed the CLA.
@patrykw-splunk
@patryk Wasielewski
Patryk Wasielewski seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You can retrigger this bot by commenting recheck in this Pull Request

@coveralls
Copy link
Collaborator

coveralls commented Feb 2, 2026

Pull Request Test Coverage Report for Build 21636244635

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 86.242%

Totals Coverage Status
Change from base Build 21471999380: 0.02%
Covered Lines: 10763
Relevant Lines: 12480

💛 - Coveralls


warnings := GetClusterManagerWarningsOnCreate(obj)
if len(warnings) != 0 {
t.Errorf("GetClusterManagerWarningsOnCreate() returned %d warnings, expected 0", len(warnings))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we just use assertions?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It applies to all tests

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Kasia, we already import testify.

@patrykw-splunk
Copy link
Collaborator Author

I have read the Code of Conduct and I hereby accept the Terms

Copy link
Collaborator

@kubabuczak kubabuczak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In current code there are 26 validation functions (search func validate across codebase) - shouldn't we replace / move them to new validation package?


for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
errs := ValidateClusterManagerCreate(tt.obj)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe t.Parallel?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These validation tests are good candidates for t.Parallel() since they're stateless - each test creates its own objects and calls pure validation functions with no shared mutable state.

However, I'd suggest not adding it for now because:

Minimal benefit - These tests are already fast (~0.7s for all validation tests). Parallelization overhead might not provide meaningful speedup.
Consistency - The rest of the codebase doesn't use t.Parallel() in table-driven tests. Adding it here would create inconsistency.
Maintenance overhead - Requires the tt := tt capture pattern which can be forgotten and cause subtle bugs:

for _, tt := range tests {
    tt := tt // easy to forget this line
    t.Run(tt.name, func(t *testing.T) {
        t.Parallel()
        // ...
    })
}

My reecommendation: Keep as-is for now. Consider adding t.Parallel() as a separate refactoring effort across all tests if test execution time becomes a concern.

Comment on lines 94 to 95
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.. maybe we should expose it as some config/env variable? I could imagine that slow k8s API server may cause timeouts. On the other hand - 10 seconds should be sufficient.

}
defer r.Body.Close()

// Decode AdmissionReview
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] in general I think that adding comments that describe obvious thing in code should be avoided. We should add them to explain "why" behind non-obvious code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants