Skip to content

fix(controller): correctly use sentinel run job check to run targeted integration tests config#688

Open
floreks wants to merge 19 commits intomainfrom
fix/sentinel-integration-test-handling
Open

fix(controller): correctly use sentinel run job check to run targeted integration tests config#688
floreks wants to merge 19 commits intomainfrom
fix/sentinel-integration-test-handling

Conversation

@floreks
Copy link
Member

@floreks floreks commented Mar 13, 2026

Refactoring and feature improvements:

  • Refactored the integration test configuration retrieval in sentinelRunController: Added a new method getIntegrationTestConfiguration to cleanly fetch the relevant configuration for a given check, and updated runTests to use this method. This makes the code more robust and easier to maintain.
  • Added buildGotestsumRunArgs utility: Centralized the construction of gotestsum command-line arguments, supporting configuration overrides (such as rerun-fails, parallelism, and process count) and added comprehensive unit tests for this logic in controller_test.go.
  • Simplified test case file creation: Replaced the previous approach with a new createTestCasesFile function that builds a single test case based on the selected configuration, improving clarity and correctness.

Utility updates:

  • Improved the test case bindings and templating logic: Refactored buildBindings to accept only the cluster fragment (instead of the entire job fragment), simplifying the interface and usage.

Integration test runner improvements:

  • Refactored the integration test runner in terratest/integration_test.go to use the new test case structure, simplifying the execution logic and making it easier to add new test types.

Test Plan

Test environment: https://console.plrl-dev-aws.onplural.sh/

Checklist

  • I have added a meaningful title and summary to convey the impact of this PR to a user.
  • I have deployed the agent to a test environment and verified that it works as expected.
  • I have added tests to cover my changes.
  • If required, I have updated the Plural documentation accordingly.

Add info-level logging to track the building and processing of integration tests within sentinel checks.
@floreks floreks requested a review from a team as a code owner March 13, 2026 12:12
@floreks floreks marked this pull request as draft March 13, 2026 12:12
@floreks floreks self-assigned this Mar 13, 2026
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 13, 2026

Greptile Summary

This PR fixes the sentinel run controller so that only the configuration matching the specific named check (fragment.Check) is used when building the integration test cases file, rather than blindly including every check in the run. It also centralises gotestsum argument construction in buildGotestsumRunArgs, simplifies the TestCase structure to a single object (removing the outer []TestCase slice and the top-level Name field), and refreshes the Go toolchain and dependencies to 1.26.1.

Several issues flagged in previous review rounds have been resolved in this iteration:

  • buildGotestsumRunArgs is now called once and the result reused for both logging and execution (no more silent divergence).
  • getIntegrationTestConfiguration guards against fragment.SentinelRun == nil before iterating.
  • The --rerun-fails=4 assertion in TestBuildGotestsumRunArgs_ConfigOverrides correctly uses mustContainArg with the =-joined form.

Two remaining items worth addressing:

  • Silent test pass on empty configurations (terratest/integration_test.go:33): if the YAML file is valid but contains zero configurations, TestSentinelIntegration exits cleanly without asserting anything.
  • Redundant if guard (terratest/integration_test.go:234): the if err != nil { require.NoError(...) } pattern is idiomatic but the surrounding if is superfluous — require.NoError already handles the nil check internally.

Confidence Score: 4/5

  • Safe to merge with minor improvements; the core fix and previous review items are properly addressed.
  • The core logic changes are correct: the targeted check lookup is properly guarded against nil inputs, buildGotestsumRunArgs is called once and the result shared, and the YAML serialisation is consistent across the controller and the test runner. The remaining issues are low-severity: one style nit and one test coverage gap (empty configurations silent-pass). Dependency and toolchain bumps are routine.
  • terratest/integration_test.go — empty configurations silent-pass and redundant error handling pattern.

Important Files Changed

Filename Overview
pkg/sentinel-harness/controller/controller.go Core refactoring: adds getIntegrationTestConfiguration, buildGotestsumRunArgs, and createTestCasesFile. Previous issues (double-call of buildGotestsumRunArgs, nil-dereference on SentinelRun) are now fixed. The removal of --test.parallel 1 as a default changes behaviour slightly but is intentional.
pkg/sentinel-harness/controller/controller_test.go New test file covering buildGotestsumRunArgs. The --rerun-fails=4 assertion now correctly uses mustContainArg with the =-joined form (addressing the previously flagged issue). One minor gap: the assertion helpers do exact string matching, so bare --rerun-fails and --rerun-fails=N are treated as different strings — any variant not explicitly checked could slip through.
pkg/sentinel-harness/controller/controller_types.go Removed the Name field from TestCase struct, consistent with the switch from a keyed list to a single per-check object.
pkg/sentinel-harness/controller/templating.go buildBindings signature simplified to accept only a cluster fragment; error return removed since it can never error.
terratest/integration_test.go Refactored to use a single TestCase instead of a slice. loadIntegrationTestCases now fails fast when the env var is unset. The type-specific sub-config nil-checks (e.g. coredns/lb) are still present inside each run* helper. One minor style issue in the error handling pattern.
terratest/types/testcase.go Mirrors the controller-side TestCase change: Name field removed, now a flat container for Configurations and Defaults.
go.mod Bumps Go toolchain to 1.26.1 and upgrades several dependencies including k8s.io/api to 0.35.x, DataDog tracer to 2.6.0, and golangci-lint to 2.11.3. One minor note: go.mod uses go 1.26.1 while some toolchain entries may still reference the old version in go.sum.

Last reviewed commit: 5ee611c

- Add unit tests for `buildGotestsumRunArgs` in `controller_test.go`.
- Remove unused `Name` field from `TestCase` struct.
- Update module dependencies in `go.sum`.
@github-actions github-actions bot added size/L and removed size/XS labels Mar 13, 2026
@socket-security
Copy link

socket-security bot commented Mar 13, 2026

- Remove unused `Name` field from `TestCase` struct.
- Refactor integration tests for better clarity and maintainability by reducing nested loops and improving variable naming.
- Implement early validation for test case configurations.
- Add support to verify `--packages=./...` args in controller unit tests.
@github-actions github-actions bot added size/XL and removed size/L labels Mar 13, 2026
@floreks floreks changed the title feat(controller): add logging for check processing fix(controller): correctly use sentinel run job check to run targeted integration tests config Mar 13, 2026
floreks and others added 2 commits March 13, 2026 17:31
- Bump Go version from 1.25.7 to 1.26.1 across multiple Dockerfiles.
- Update all relevant build and workflow configurations to use the new Go version.
floreks added 4 commits March 13, 2026 17:35
- Bump golangci-lint version from v2.8.0 to v2.11.3 in GitHub Actions CI configuration and go.mod.
- Upgrade multiple indirect dependencies to their latest versions in go.mod for improved stability and performance.
- Bump golangci-lint version from v2.8.0 to v2.11.3 in GitHub Actions CI configuration and go.mod.
- Upgrade multiple indirect dependencies to their latest versions in go.mod for improved stability and performance.
- Add `.PHONY: build` target to Makefile for building all binaries.
- Upgrade multiple dependencies to their latest versions in go.mod and go.sum for improved stability and performance.
…luralsh/deployment-operator into fix/sentinel-integration-test-handling
@github-actions github-actions bot added size/XXL and removed size/XL labels Mar 13, 2026
@socket-security
Copy link

socket-security bot commented Mar 13, 2026

Warning

Review the following alerts detected in dependencies.

According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.

Action Severity Alert  (click "▶" to expand/collapse)
Warn High
Obfuscated code: golang github.com/cert-manager/cert-manager is 98.0% likely obfuscated

Confidence: 0.98

Location: Package overview

From: go.modgolang/github.com/cert-manager/cert-manager@v1.19.3

ℹ Read more on: This package | This alert | What is obfuscated code?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should not obfuscate their code. Consider not using packages with obfuscated code.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore golang/github.com/cert-manager/cert-manager@v1.19.3. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

View full report

floreks added 5 commits March 13, 2026 17:57
chore(deps): roll back GO_FIPS_IMAGE_TAG and update klog

- Rollback GO_FIPS_IMAGE_TAG from 1.26.1 to 1.24.2 in FIPS Dockerfile.
- Update controller to use klog for logging while formatting output with `fmt.Fprintf`.
```
- Upgrade k8s.io/api, k8s.io/client-go, k8s.io/apiserver, and k8s.io/component-base to v0.35.2.
- Add k8s.io/klog v1.0.0 for improved logging capabilities.
- Use `replace` directive for k8s.io/cloud-provider v0.35.2.
- Upgrade `k8s.io/apiextensions-apiserver` to v0.35.2.
- Add indirect dependencies: `github.com/NYTimes/gziphandler`, `gopkg.in/natefinch/lumberjack.v2`, `github.com/coreos/go-semver`, and more for enhanced functionalities and performance.
…TAG`

- Remove unused dependencies from go.mod and go.sum for a cleaner configuration.
- Downgrade GO_FIPS_IMAGE_TAG from 1.26.1
floreks added 2 commits March 16, 2026 11:47
- Refactor rerun-failures logic to correctly handle rerun counts using `lo.FromPtr`.
- Simplify the condition for appending rerun-failures argument based on rerun count.
…inel fragment checks`

- Add validation for test case configurations to ensure they have names and types.
- Modify running of gotestsum with corrected args in controller.
- Add check for `SentinelRun` presence in test configuration fragments.
@floreks
Copy link
Member Author

floreks commented Mar 16, 2026

@greptileai

- Change argument check from `mustContainArgPair` to `mustContainArg` for `--rerun-fails=4`.
@floreks
Copy link
Member Author

floreks commented Mar 16, 2026

@greptileai fixed tests, PTAL

@floreks floreks marked this pull request as ready for review March 16, 2026 11:06
@linear
Copy link

linear bot commented Mar 18, 2026

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant