Skip to content

feat: Add comprehensive webhook validations for CRD configuration#1762

Open
patrykw-splunk wants to merge 9 commits intodevelopfrom
feature/add-missing-webhook-validations
Open

feat: Add comprehensive webhook validations for CRD configuration#1762
patrykw-splunk wants to merge 9 commits intodevelopfrom
feature/add-missing-webhook-validations

Conversation

@patrykw-splunk
Copy link
Collaborator

Description

This PR enhances the Splunk Operator's webhook validation layer with comprehensive validation rules to catch configuration errors early and provide clear error messages to users.

Key Changes

  • appsRepoPollInterval: Validates range (0 or 60-86400 seconds)
  • appSources uniqueness: Ensures Location + Scope combinations are unique
  • premiumAppsProps: Requires premiumAppsProps.type when scope=premiumApps
  • extraEnv uniqueness: Prevents duplicate environment variable names
  • imagePullSecrets uniqueness: Prevents duplicate secret references
  • Probe fields: Validates minimum values for probe configuration fields
  • IndexerCluster replicas: Adds kubebuilder default=3 and minimum=3 annotations
  • Resource requirements: Validates that CPU/memory requests do not exceed limits
  • SmartStore: Validates that indexes have volumes configured, volumeName references exist, and volumeName is provided (directly or via defaults)
  • StorageClassSpec: Validates mutual exclusivity between ephemeralStorage and storageClassName/storageCapacity

Testing and Verification

Added Unit 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.

Patryk Wasielewski added 8 commits March 9, 2026 13:33
- Add appsRepoPollInterval validation:
  - Default: 0 (disabled)
  - Minimum: 0, Maximum: 86400 (1 day)
  - Values between 1-59 are rejected (must be 0 or >= 60)

- Add appSources uniqueness validation:
  - Location + Scope combination must be unique across appSources
  - Uses defaults.scope when scope is not specified in appSource
  - volumeName is NOT part of uniqueness check

- Add unit tests for all new validations
- Validate that premiumAppsProps.type is required when scope is 'premiumApps'
- Check both source-level and defaults-level premiumAppsProps.type
- Add unit tests for premiumAppsProps validation scenarios
- Validate that environment variable names in spec.extraEnv are unique
- Report duplicate names with reference to the first occurrence
- Add unit tests for extraEnv uniqueness validation
- Validate that secret names in spec.imagePullSecrets are unique
- Report duplicate names with reference to the first occurrence
- Add unit tests for imagePullSecrets uniqueness validation
- Validate livenessProbe, readinessProbe, and startupProbe configurations
- initialDelaySeconds: minimum 0
- timeoutSeconds: minimum 1
- periodSeconds: minimum 1
- failureThreshold: minimum 1
- Add unit tests for probe validation scenarios
- Validate that memory request does not exceed memory limit
- Validate that cpu request does not exceed cpu limit
- Add unit tests for resource requirements validation
- Validate that indexes require at least one volume to be configured
- Validate that index volumeName references an existing volume in volumes list
- Validate that index has volumeName or defaults.volumeName provided
- Update and add unit tests for SmartStore validation
- Validate that ephemeralStorage is mutually exclusive with storageClassName
- Validate that ephemeralStorage is mutually exclusive with storageCapacity
- Add unit tests for ephemeralStorage mutual exclusivity scenarios
@github-actions
Copy link
Contributor

github-actions bot commented Mar 10, 2026

CLA Assistant Lite bot:
Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you 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


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

@github-actions
Copy link
Contributor

CLA Assistant Lite bot: All contributors have NOT signed the COC Document


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


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

@patrykw-splunk
Copy link
Collaborator Author

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

}

// Validate imagePullSecrets uniqueness by Name
seenSecretNames := make(map[string]int) // map name -> first index seen
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could extract this code into a separate function since the same code is used more than once.

- Add ValidationContext to carry Kubernetes client for resource lookups
- Extend Validator interface with context-aware validation methods
- Implement ValidateImagePullSecretsExistence to verify secrets exist
- Update all CRD validators with context-aware validation functions
- Pass manager client to webhook server for API access
- Update ValidationWebhook.md documentation with new validation rules
- Add unit tests for imagePullSecrets existence validation

This enables the webhook to reject CRs that reference non-existent
secrets in spec.imagePullSecrets, providing early feedback to users.
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.

2 participants