-
Notifications
You must be signed in to change notification settings - Fork 228
NO-JIRA: E2E: Preserve CVO state when bypassing VAP #1368
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
Open
gcs278
wants to merge
1
commit into
openshift:master
Choose a base branch
from
gcs278:e2e-preserve-cvo-replicas
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.
Open
Changes from all commits
Commits
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 |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ import ( | |
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/types" | ||
| "k8s.io/apimachinery/pkg/util/wait" | ||
| "k8s.io/utils/ptr" | ||
|
|
||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1" | ||
|
|
@@ -1184,10 +1185,34 @@ func scaleDeployment(t *testing.T, namespace, name string, replicas int32) error | |
| }) | ||
| } | ||
|
|
||
| // getCVOReplicas returns the current replica count of the CVO deployment. | ||
| func getCVOReplicas(t *testing.T) (int32, error) { | ||
| t.Helper() | ||
| nsName := types.NamespacedName{Namespace: cvoNamespace, Name: cvoDeploymentName} | ||
| cvo := &appsv1.Deployment{} | ||
|
|
||
| err := wait.PollUntilContextTimeout(context.Background(), 1*time.Second, 30*time.Second, false, func(ctx context.Context) (bool, error) { | ||
| if err := kclient.Get(ctx, nsName, cvo); err != nil { | ||
| t.Logf("failed to get cvo deployment: %v, retrying...", err) | ||
| return false, nil | ||
| } | ||
| return true, nil | ||
| }) | ||
| if err != nil { | ||
| return 0, fmt.Errorf("failed to get cvo deployment: %w", err) | ||
| } | ||
|
|
||
| return ptr.Deref(cvo.Spec.Replicas, 1), nil | ||
| } | ||
|
|
||
| // vapManager helps to disable the VAP resource which is managed by CVO. | ||
| // Handles both disabling (to allow tests to modify/test CRDs) and restoration (test cleanup). | ||
| // The goal is not to test VAP/CVO behavior - just to enable test execution and cleanup. | ||
| type vapManager struct { | ||
| t *testing.T | ||
| name string | ||
| t *testing.T | ||
| name string | ||
| initialCVOReplicas int32 | ||
| savedVAP *admissionregistrationv1.ValidatingAdmissionPolicy | ||
| } | ||
|
|
||
| // newVAPManager returns a new instance of VAPManager. | ||
|
|
@@ -1200,25 +1225,63 @@ func newVAPManager(t *testing.T, vapName string) *vapManager { | |
|
|
||
| // disable scales down CVO and removes the VAP resource. | ||
| func (m *vapManager) disable() (error, func()) { | ||
| // Save the current replica count before scaling down | ||
| replicas, err := getCVOReplicas(m.t) | ||
| if err != nil { | ||
| return err, func() {} | ||
| } | ||
| m.initialCVOReplicas = replicas | ||
|
|
||
| recoverCVO := func() { | ||
| if err := scaleDeployment(m.t, cvoNamespace, cvoDeploymentName, m.initialCVOReplicas); err != nil { | ||
| m.t.Errorf("failed to scale up cvo: %v", err) | ||
| } | ||
| } | ||
|
|
||
| if err := scaleDeployment(m.t, cvoNamespace, cvoDeploymentName, 0); err != nil { | ||
| return fmt.Errorf("failed to scale down cvo: %w", err), func() { /*scale down didn't work, nothing to do*/ } | ||
| } | ||
|
|
||
| // Save VAP before deleting it so we can restore it later in case CVO isn't running | ||
| vap := &admissionregistrationv1.ValidatingAdmissionPolicy{} | ||
| name := types.NamespacedName{Name: m.name} | ||
| if err := kclient.Get(context.Background(), name, vap); err != nil { | ||
| return fmt.Errorf("failed to get vap %q: %w", m.name, err), recoverCVO | ||
| } | ||
|
Comment on lines
+1246
to
+1250
Contributor
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. CVO's replicas is retrieved with a poll. For consistency and test resiliency we can do a polled |
||
|
|
||
| // Save a copy before deleting | ||
| m.savedVAP = vap.DeepCopy() | ||
|
|
||
| if err := deleteExistingVAP(m.t, m.name); err != nil { | ||
| return fmt.Errorf("failed to delete vap %q: %w", m.name, err), func() { | ||
| if err := scaleDeployment(m.t, cvoNamespace, cvoDeploymentName, 1); err != nil { | ||
| m.t.Errorf("failed to scale up cvo: %v", err) | ||
| } | ||
| } | ||
| return fmt.Errorf("failed to delete vap %q: %w", m.name, err), recoverCVO | ||
| } | ||
|
|
||
| return nil, nil | ||
| } | ||
|
|
||
| // Enable scales up CVO and waits until the VAP is recreated. | ||
| // This is NOT testing VAP/CVO behavior - just to restore cluster state. | ||
| // Uses CVO to restore VAP if it was running, otherwise manually recreates the saved VAP. | ||
| func (m *vapManager) enable() { | ||
| if err := scaleDeployment(m.t, cvoNamespace, cvoDeploymentName, 1); err != nil { | ||
| m.t.Errorf("failed to scale up cvo: %v", err) | ||
| } else if err := assertVAP(m.t, m.name); err != nil { | ||
| m.t.Errorf("failed to find vap %q: %v", m.name, err) | ||
| // Only restore VAP manually if CVO is disabled (it won't recreate it) | ||
| if m.initialCVOReplicas == 0 { | ||
| if m.savedVAP != nil { | ||
| // Clear resource version to allow recreation | ||
| m.savedVAP.ResourceVersion = "" | ||
| if err := kclient.Create(context.Background(), m.savedVAP); err != nil { | ||
| if !kerrors.IsAlreadyExists(err) { | ||
| m.t.Errorf("failed to restore vap %q: %v", m.name, err) | ||
| } | ||
| } else { | ||
| m.t.Logf("Manually restored VAP %q (CVO is disabled)", m.name) | ||
| } | ||
| } | ||
| } else { | ||
| if err := scaleDeployment(m.t, cvoNamespace, cvoDeploymentName, m.initialCVOReplicas); err != nil { | ||
| m.t.Errorf("failed to scale up cvo: %v", err) | ||
| } else if err := assertVAP(m.t, m.name); err != nil { | ||
| m.t.Errorf("failed to find vap %q: %v", m.name, err) | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
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.