-
Notifications
You must be signed in to change notification settings - Fork 267
test/encryption: add InvalidImageRecoveryScenario for KMS plugin imag… #2243
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
Draft
gangwgr
wants to merge
4
commits into
openshift:master
Choose a base branch
from
gangwgr:kms-invalid-image-recovery
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
de1745f
test/encryption: add InvalidImageRecoveryScenario for KMS plugin imag…
gangwgr f307d1c
Rename AppRole datakeys to role-id and secret-id
ardaguclu 9e7a937
In-place field update for KMS mode regardless of the convergence
ardaguclu d94ed61
test/kms: add InvalidImageVaultEncryptionProvider for degradation tests
gangwgr 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,10 +8,10 @@ import ( | |
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
| "k8s.io/apimachinery/pkg/util/rand" | ||
|
|
||
| "k8s.io/apimachinery/pkg/runtime/schema" | ||
| "k8s.io/apimachinery/pkg/util/rand" | ||
|
|
||
| configv1 "github.com/openshift/api/config/v1" | ||
| ) | ||
|
|
@@ -277,3 +277,81 @@ func TestEncryptionRotation(ctx context.Context, t testing.TB, scenario Rotation | |
|
|
||
| // TODO: assert conditions - operator and encryption migration controller must report status as active not progressing, and not failing for all scenarios | ||
| } | ||
|
|
||
| // InvalidImageRecoveryScenario tests that an invalid KMS plugin image causes | ||
| // the cluster to degrade and that correcting the image restores normal operation. | ||
| // | ||
| // Arda's scenario: | ||
| // 1. Enable KMS with invalid image | ||
| // 2. Attempt to switch to aescbc (cluster should be stuck on KMS) | ||
| // 3. See degraded | ||
| // 4. Update with KMS with valid image | ||
| // 5. See everything works | ||
| type InvalidImageRecoveryScenario struct { | ||
| BasicScenario | ||
| // InvalidImageProvider is the KMS EncryptionProvider configured with an invalid | ||
| // (non-existent or broken) KMS plugin image. Enabling this should cause degradation. | ||
| InvalidImageProvider EncryptionProvider | ||
| // ValidImageProvider is the KMS EncryptionProvider configured with the correct | ||
| // KMS plugin image. Applying this after degradation should restore the cluster. | ||
| ValidImageProvider EncryptionProvider | ||
| // WaitForDegraded should block until the operator reports a degraded condition. | ||
| WaitForDegraded func(ctx context.Context, t testing.TB) | ||
| // WaitForRecovery should block until the operator reports a healthy condition | ||
| // and encryption is fully operational. | ||
| WaitForRecovery func(ctx context.Context, t testing.TB) | ||
| } | ||
|
|
||
| // TestEncryptionInvalidImageRecovery tests that: | ||
| // 1. Enabling KMS with an invalid plugin image causes degradation | ||
| // 2. The cluster remains stuck and cannot migrate to another mode (e.g. aescbc) | ||
| // 3. Fixing the KMS config with a valid image restores the cluster | ||
| func TestEncryptionInvalidImageRecovery(ctx context.Context, t testing.TB, scenario InvalidImageRecoveryScenario) { | ||
| e := NewE(t, PrintEventsOnFailure(scenario.OperatorNamespace)) | ||
| require.NotNil(t, scenario.WaitForDegraded, "WaitForDegraded must not be nil") | ||
| require.NotNil(t, scenario.WaitForRecovery, "WaitForRecovery must not be nil") | ||
| require.Equal(t, configv1.EncryptionTypeKMS, scenario.InvalidImageProvider.Type, "InvalidImageProvider must be KMS type") | ||
| require.Equal(t, configv1.EncryptionTypeKMS, scenario.ValidImageProvider.Type, "ValidImageProvider must be KMS type") | ||
|
|
||
| cs := GetClients(e) | ||
|
|
||
| // step 1: enable KMS with invalid image (set config but don't wait for completion) | ||
| t.Log("Setting KMS encryption with invalid plugin image") | ||
| if scenario.InvalidImageProvider.Setup != nil { | ||
| scenario.InvalidImageProvider.Setup(ctx, e) | ||
| } | ||
| apiServer, err := cs.ApiServerConfig.Get(ctx, "cluster", metav1.GetOptions{}) | ||
| require.NoError(t, err) | ||
| apiServer.Spec.Encryption = scenario.InvalidImageProvider.APIServerEncryption | ||
| _, err = cs.ApiServerConfig.Update(ctx, apiServer, metav1.UpdateOptions{}) | ||
| require.NoError(t, err) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| // step 2: attempt to switch to aescbc — cluster should remain stuck on KMS | ||
| t.Log("Attempting to switch to aescbc (cluster should remain stuck on KMS)") | ||
| apiServer, err = cs.ApiServerConfig.Get(ctx, "cluster", metav1.GetOptions{}) | ||
| require.NoError(t, err) | ||
| apiServer.Spec.Encryption = configv1.APIServerEncryption{Type: configv1.EncryptionTypeAESCBC} | ||
| _, err = cs.ApiServerConfig.Update(ctx, apiServer, metav1.UpdateOptions{}) | ||
| require.NoError(t, err) | ||
|
|
||
| // step 3: wait for degraded | ||
| t.Log("Waiting for operator to report degraded status") | ||
| scenario.WaitForDegraded(ctx, e) | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assert the mode remains KMS after the failed switch attempt. After Line 334, the test only waits for degraded status. It does not explicitly verify the cluster stayed on KMS, so step 2 can pass without validating the intended behavior. Proposed fix func TestEncryptionInvalidImageRecovery(ctx context.Context, t testing.TB, scenario InvalidImageRecoveryScenario) {
e := NewE(t, PrintEventsOnFailure(scenario.OperatorNamespace))
+ require.NotNil(t, scenario.AssertFunc, "AssertFunc must not be nil")
require.NotNil(t, scenario.WaitForDegraded, "WaitForDegraded must not be nil")
require.NotNil(t, scenario.WaitForRecovery, "WaitForRecovery must not be nil")
@@
// step 3: wait for degraded
t.Log("Waiting for operator to report degraded status")
scenario.WaitForDegraded(ctx, e)
+ scenario.AssertFunc(e, cs, configv1.EncryptionTypeKMS, scenario.Namespace, scenario.LabelSelector)🤖 Prompt for AI Agents |
||
| // step 4: fix the config with valid KMS image | ||
| t.Log("Updating KMS encryption with valid plugin image to recover") | ||
| if scenario.ValidImageProvider.Setup != nil { | ||
| scenario.ValidImageProvider.Setup(ctx, e) | ||
| } | ||
| apiServer, err = cs.ApiServerConfig.Get(ctx, "cluster", metav1.GetOptions{}) | ||
| require.NoError(t, err) | ||
| apiServer.Spec.Encryption = scenario.ValidImageProvider.APIServerEncryption | ||
| _, err = cs.ApiServerConfig.Update(ctx, apiServer, metav1.UpdateOptions{}) | ||
| require.NoError(t, err) | ||
|
|
||
| // step 5: wait for recovery — everything should work | ||
| t.Log("Waiting for operator to recover with valid KMS image") | ||
| scenario.WaitForRecovery(ctx, e) | ||
|
|
||
| t.Log("Invalid image recovery test passed") | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this scenario nicely exercises the in-place field update case which will be added by #2241.