Skip to content

Commit 4d34c26

Browse files
committed
E2E: Preserve CVO state when bypassing VAP
Store and restore CVO's initial replica count instead of hardcoding 1. Fixes debugging workflows where CVO is intentionally disabled.
1 parent add0516 commit 4d34c26

1 file changed

Lines changed: 39 additions & 6 deletions

File tree

test/e2e/util_gatewayapi_test.go

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,10 +1184,34 @@ func scaleDeployment(t *testing.T, namespace, name string, replicas int32) error
11841184
})
11851185
}
11861186

1187+
// getCVOReplicas returns the current replica count of the CVO deployment.
1188+
func getCVOReplicas(t *testing.T) (int32, error) {
1189+
t.Helper()
1190+
nsName := types.NamespacedName{Namespace: cvoNamespace, Name: cvoDeploymentName}
1191+
cvo := &appsv1.Deployment{}
1192+
1193+
err := wait.PollUntilContextTimeout(context.Background(), 1*time.Second, 30*time.Second, false, func(ctx context.Context) (bool, error) {
1194+
if err := kclient.Get(ctx, nsName, cvo); err != nil {
1195+
t.Logf("failed to get cvo deployment: %v, retrying...", err)
1196+
return false, nil
1197+
}
1198+
return true, nil
1199+
})
1200+
if err != nil {
1201+
return 0, fmt.Errorf("failed to get cvo deployment: %w", err)
1202+
}
1203+
1204+
if cvo.Spec.Replicas != nil {
1205+
return *cvo.Spec.Replicas, nil
1206+
}
1207+
return 1, nil
1208+
}
1209+
11871210
// vapManager helps to disable the VAP resource which is managed by CVO.
11881211
type vapManager struct {
1189-
t *testing.T
1190-
name string
1212+
t *testing.T
1213+
name string
1214+
initialCVOReplicas int32
11911215
}
11921216

11931217
// newVAPManager returns a new instance of VAPManager.
@@ -1200,12 +1224,19 @@ func newVAPManager(t *testing.T, vapName string) *vapManager {
12001224

12011225
// disable scales down CVO and removes the VAP resource.
12021226
func (m *vapManager) disable() (error, func()) {
1227+
// Save the current replica count before scaling down
1228+
replicas, err := getCVOReplicas(m.t)
1229+
if err != nil {
1230+
return err, nil
1231+
}
1232+
m.initialCVOReplicas = replicas
1233+
12031234
if err := scaleDeployment(m.t, cvoNamespace, cvoDeploymentName, 0); err != nil {
12041235
return fmt.Errorf("failed to scale down cvo: %w", err), func() { /*scale down didn't work, nothing to do*/ }
12051236
}
12061237
if err := deleteExistingVAP(m.t, m.name); err != nil {
12071238
return fmt.Errorf("failed to delete vap %q: %w", m.name, err), func() {
1208-
if err := scaleDeployment(m.t, cvoNamespace, cvoDeploymentName, 1); err != nil {
1239+
if err := scaleDeployment(m.t, cvoNamespace, cvoDeploymentName, m.initialCVOReplicas); err != nil {
12091240
m.t.Errorf("failed to scale up cvo: %v", err)
12101241
}
12111242
}
@@ -1215,10 +1246,12 @@ func (m *vapManager) disable() (error, func()) {
12151246

12161247
// Enable scales up CVO and waits until the VAP is recreated.
12171248
func (m *vapManager) enable() {
1218-
if err := scaleDeployment(m.t, cvoNamespace, cvoDeploymentName, 1); err != nil {
1249+
if err := scaleDeployment(m.t, cvoNamespace, cvoDeploymentName, m.initialCVOReplicas); err != nil {
12191250
m.t.Errorf("failed to scale up cvo: %v", err)
1220-
} else if err := assertVAP(m.t, m.name); err != nil {
1221-
m.t.Errorf("failed to find vap %q: %v", m.name, err)
1251+
} else if m.initialCVOReplicas > 0 {
1252+
if err := assertVAP(m.t, m.name); err != nil {
1253+
m.t.Errorf("failed to find vap %q: %v", m.name, err)
1254+
}
12221255
}
12231256
}
12241257

0 commit comments

Comments
 (0)