-
Notifications
You must be signed in to change notification settings - Fork 221
Add StorageVersionMigrator controller (opt-in, default off) #5362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e607823
Add StorageVersionMigrator controller (opt-in, default off)
ChrisJBurns d6ca39c
Address PR review feedback
ChrisJBurns 1199a8f
Sync single-tenancy chainsaw RBAC fixture with regenerated ClusterRole
ChrisJBurns d1c7da0
Merge branch 'main' into chris/svm-controller
ChrisJBurns b491b9a
Merge branch 'main' into chris/svm-controller
amirejaz 435f547
Merge branch 'main' into chris/svm-controller
ChrisJBurns b783471
Add unit tests for StorageVersionMigrator controller helpers
ChrisJBurns a0cceb0
Extend SVM unit tests to ensureInitialized and Reconcile early returns
ChrisJBurns e778b70
Add fake-client unit tests for restoreOne/restoreCRs/patchStoredVersions
ChrisJBurns 047047d
Refactor SVM unit tests for conciseness
ChrisJBurns 9c15e0b
Address second-round PR review feedback (F1, F2, F3, F4, F5, F6)
ChrisJBurns bad9fc3
Address test-review feedback (T2, T3, T6, T7 + coverage gaps)
ChrisJBurns 40b74c5
Fix lint findings on SVM unit tests
ChrisJBurns 43333c1
Merge branch 'main' into chris/svm-controller
ChrisJBurns a29a740
Fix codespell findings in SVM unit tests
ChrisJBurns 9af966c
Merge branch 'main' into chris/svm-controller
ChrisJBurns 8846ce6
Update cmd/thv-operator/controllers/storageversionmigrator_controller.go
ChrisJBurns b7c4116
Address JAORMX's PR review findings
ChrisJBurns 0582b75
Recover lost controller changes from the previous rebase
ChrisJBurns a560016
Fix CI failures from review-feedback commit
ChrisJBurns File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| // SPDX-FileCopyrightText: Copyright 2025 Stacklok, Inc. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package app | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // TestIsStorageVersionMigratorEnabled exercises the env-var contract for the | ||
| // StorageVersionMigrator feature flag. The function must: | ||
| // - default to (false, nil) when the env var is unset (the controller is | ||
| // opt-in for this release), | ||
| // - accept strconv.ParseBool's full truth-table for explicit values, | ||
| // - fail loudly on unparsable values so a misconfigured admin sees a | ||
| // startup error instead of silently disabled migration. | ||
| // | ||
| // The error-case rows assert on both the env-var name AND the offending | ||
| // value being present in the error message, so a future refactor that | ||
| // drops either fragment fails this test. | ||
| func TestIsStorageVersionMigratorEnabled(t *testing.T) { | ||
| // Intentionally NOT t.Parallel(): subtests use t.Setenv, which | ||
| // panics if the test (or any ancestor) is parallel. Subtests are | ||
| // also serial for the same reason. The trade-off is negligible — | ||
| // the test is sub-millisecond — and matches Go 1.20+ guidance for | ||
| // env-var-driven tests. | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| setEnv bool | ||
| envValue string | ||
| wantEnabled bool | ||
| wantErr bool | ||
| }{ | ||
| { | ||
| name: "unset defaults to disabled", | ||
| setEnv: false, | ||
| wantEnabled: false, | ||
| wantErr: false, | ||
| }, | ||
| { | ||
| name: "explicit true enables", | ||
| setEnv: true, | ||
| envValue: "true", | ||
| wantEnabled: true, | ||
| wantErr: false, | ||
| }, | ||
| { | ||
| name: "explicit false disables", | ||
| setEnv: true, | ||
| envValue: "false", | ||
| wantEnabled: false, | ||
| wantErr: false, | ||
| }, | ||
| { | ||
| name: "explicit 1 enables (ParseBool truthy)", | ||
| setEnv: true, | ||
| envValue: "1", | ||
| wantEnabled: true, | ||
| wantErr: false, | ||
| }, | ||
| { | ||
| name: "explicit 0 disables (ParseBool falsy)", | ||
| setEnv: true, | ||
| envValue: "0", | ||
| wantEnabled: false, | ||
| wantErr: false, | ||
| }, | ||
| { | ||
| name: "unparsable value errors with env-var name and bad value", | ||
| setEnv: true, | ||
| envValue: "garbage", | ||
| wantEnabled: false, | ||
| wantErr: true, | ||
| }, | ||
| { | ||
| name: "empty string errors (ParseBool rejects empty)", | ||
| setEnv: true, | ||
| envValue: "", | ||
| wantEnabled: false, | ||
| wantErr: true, | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range tests { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| // Subtests intentionally do NOT call t.Parallel(): t.Setenv | ||
| // is incompatible with a parallel *testing.T (it panics with | ||
| // "test using t.Setenv ... can not use t.Parallel"). The | ||
| // outer test still runs in parallel with other tests in the | ||
| // package — only sibling subtests of this test serialize, | ||
| // which is fine because t.Setenv restores the prior value | ||
| // at the subtest's end. | ||
| if tc.setEnv { | ||
| t.Setenv(envEnableStorageVersionMigrator, tc.envValue) | ||
| } | ||
|
|
||
| got, err := isStorageVersionMigratorEnabled() | ||
|
|
||
| if tc.wantErr { | ||
| require.Error(t, err) | ||
| assert.Contains(t, err.Error(), envEnableStorageVersionMigrator, | ||
| "error message must name the env var so admins can find the misconfiguration") | ||
| assert.Contains(t, err.Error(), `"`+tc.envValue+`"`, | ||
| "error message must quote the offending value so admins can spot typos") | ||
| } else { | ||
| require.NoError(t, err) | ||
| } | ||
| assert.Equal(t, tc.wantEnabled, got) | ||
| }) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.