Skip to content

Commit 72ca5d3

Browse files
committed
changes from review
1 parent 391139d commit 72ca5d3

5 files changed

Lines changed: 427 additions & 35 deletions

File tree

pkg/cache/validating_cache.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@ func (c *ValidatingCache[K, V]) Set(key K, value V) {
162162
c.lruCache.Add(key, value)
163163
}
164164

165+
// Delete removes the entry for key from the cache, invoking onEvict if the key
166+
// was present. It is a no-op if the key does not exist.
167+
func (c *ValidatingCache[K, V]) Delete(key K) {
168+
c.lruCache.Remove(key)
169+
}
170+
165171
// Len returns the number of entries currently in the cache.
166172
func (c *ValidatingCache[K, V]) Len() int {
167173
return c.lruCache.Len()

test/e2e/thv-operator/virtualmcp/helpers.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ func GetVMCPNodePort(
828828
}
829829

830830
// Verify the HTTP server is ready to handle requests
831-
if err := checkHTTPHealthReady(nodePort, 2*time.Second); err != nil {
831+
if err := checkHTTPHealthReady(nodePort); err != nil {
832832
return fmt.Errorf("nodePort %d accessible but HTTP server not ready: %w", nodePort, err)
833833
}
834834

@@ -854,8 +854,8 @@ func checkPortAccessible(nodePort int32, timeout time.Duration) error {
854854

855855
// checkHTTPHealthReady verifies the HTTP server is ready by checking the /health endpoint.
856856
// This is more reliable than just TCP check as it ensures the application is serving requests.
857-
func checkHTTPHealthReady(nodePort int32, timeout time.Duration) error {
858-
httpClient := &http.Client{Timeout: timeout}
857+
func checkHTTPHealthReady(nodePort int32) error {
858+
httpClient := &http.Client{Timeout: 2 * time.Second}
859859
url := fmt.Sprintf("http://localhost:%d/health", nodePort)
860860

861861
resp, err := httpClient.Get(url)

test/e2e/thv-operator/virtualmcp/mcpserver_scaling_test.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,17 @@ import (
2929
"github.com/stacklok/toolhive/test/e2e/thv-operator/testutil"
3030
)
3131

32+
const proxyPort = int32(8080)
33+
3234
// deployRedis creates a single-replica Redis Deployment and ClusterIP Service.
3335
// Returns after the deployment has at least one ready replica.
34-
func deployRedis(namespace, name string, timeout, pollInterval time.Duration) {
36+
func deployRedis(name string) {
3537
labels := map[string]string{"app": name}
3638

3739
deployment := &appsv1.Deployment{
3840
ObjectMeta: metav1.ObjectMeta{
3941
Name: name,
40-
Namespace: namespace,
42+
Namespace: defaultNamespace,
4143
Labels: labels,
4244
},
4345
Spec: appsv1.DeploymentSpec{
@@ -69,7 +71,7 @@ func deployRedis(namespace, name string, timeout, pollInterval time.Duration) {
6971
service := &corev1.Service{
7072
ObjectMeta: metav1.ObjectMeta{
7173
Name: name,
72-
Namespace: namespace,
74+
Namespace: defaultNamespace,
7375
},
7476
Spec: corev1.ServiceSpec{
7577
Selector: labels,
@@ -86,20 +88,20 @@ func deployRedis(namespace, name string, timeout, pollInterval time.Duration) {
8688
ginkgo.By("Waiting for Redis to become ready")
8789
gomega.Eventually(func() bool {
8890
dep := &appsv1.Deployment{}
89-
if err := k8sClient.Get(ctx, types.NamespacedName{Name: name, Namespace: namespace}, dep); err != nil {
91+
if err := k8sClient.Get(ctx, types.NamespacedName{Name: name, Namespace: defaultNamespace}, dep); err != nil {
9092
return false
9193
}
9294
return dep.Status.ReadyReplicas > 0
93-
}, timeout, pollInterval).Should(gomega.BeTrue(), "Redis should be ready")
95+
}, e2eTimeout, e2ePollInterval).Should(gomega.BeTrue(), "Redis should be ready")
9496
}
9597

9698
// cleanupRedis removes the Redis Deployment and Service.
97-
func cleanupRedis(namespace, name string) {
99+
func cleanupRedis(name string) {
98100
_ = k8sClient.Delete(ctx, &appsv1.Deployment{
99-
ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: namespace},
101+
ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: defaultNamespace},
100102
})
101103
_ = k8sClient.Delete(ctx, &corev1.Service{
102-
ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: namespace},
104+
ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: defaultNamespace},
103105
})
104106
}
105107

@@ -160,9 +162,9 @@ func portForwardToPod(podName string) (int, func(), error) {
160162
kubeconfigArg := fmt.Sprintf("--kubeconfig=%s", kubeconfig)
161163
//nolint:gosec // kubeconfig, podName, and ports are test-controlled values
162164
cmd := exec.Command("kubectl", kubeconfigArg,
163-
"-n", "default", "port-forward",
165+
"-n", defaultNamespace, "port-forward",
164166
fmt.Sprintf("pod/%s", podName),
165-
fmt.Sprintf("%d:%d", localPort, 8080))
167+
fmt.Sprintf("%d:%d", localPort, proxyPort))
166168
if err := cmd.Start(); err != nil {
167169
return 0, nil, fmt.Errorf("failed to start port-forward to %s: %w", podName, err)
168170
}
@@ -190,10 +192,8 @@ func portForwardToPod(podName string) (int, func(), error) {
190192

191193
var _ = ginkgo.Describe("MCPServer Cross-Replica Session Routing with Redis", func() {
192194
const (
193-
timeout = time.Minute * 5
194-
pollInterval = time.Second * 2
195-
defaultNamespace = "default"
196-
proxyPort = int32(8080)
195+
timeout = time.Minute * 5
196+
pollInterval = time.Second * 2
197197
)
198198

199199
ginkgo.Context("When MCPServer has backendReplicas=2 and proxy runner restarts", ginkgo.Ordered, func() {
@@ -211,7 +211,7 @@ var _ = ginkgo.Describe("MCPServer Cross-Replica Session Routing with Redis", fu
211211
nodePortName = mcpServerName + "-nodeport"
212212

213213
ginkgo.By("Deploying Redis for session storage")
214-
deployRedis(defaultNamespace, redisName, timeout, pollInterval)
214+
deployRedis(redisName)
215215

216216
replicas := int32(1)
217217
backendReplicas := int32(2)
@@ -258,7 +258,7 @@ var _ = ginkgo.Describe("MCPServer Cross-Replica Session Routing with Redis", fu
258258
if err := checkPortAccessible(nodePort, 1*time.Second); err != nil {
259259
return fmt.Errorf("nodePort %d not accessible: %w", nodePort, err)
260260
}
261-
if err := checkHTTPHealthReady(nodePort, 2*time.Second); err != nil {
261+
if err := checkHTTPHealthReady(nodePort); err != nil {
262262
return fmt.Errorf("nodePort %d not ready: %w", nodePort, err)
263263
}
264264
return nil
@@ -272,7 +272,7 @@ var _ = ginkgo.Describe("MCPServer Cross-Replica Session Routing with Redis", fu
272272
_ = k8sClient.Delete(ctx, &corev1.Service{
273273
ObjectMeta: metav1.ObjectMeta{Name: nodePortName, Namespace: defaultNamespace},
274274
})
275-
cleanupRedis(defaultNamespace, redisName)
275+
cleanupRedis(redisName)
276276

277277
gomega.Eventually(func() bool {
278278
err := k8sClient.Get(ctx, types.NamespacedName{Name: mcpServerName, Namespace: defaultNamespace}, &mcpv1alpha1.MCPServer{})
@@ -328,7 +328,7 @@ var _ = ginkgo.Describe("MCPServer Cross-Replica Session Routing with Redis", fu
328328

329329
ginkgo.By("Waiting for NodePort to be accessible on the new pod")
330330
gomega.Eventually(func() error {
331-
if err := checkHTTPHealthReady(nodePort, 2*time.Second); err != nil {
331+
if err := checkHTTPHealthReady(nodePort); err != nil {
332332
return fmt.Errorf("nodePort %d not ready after restart: %w", nodePort, err)
333333
}
334334
return nil
@@ -374,7 +374,7 @@ var _ = ginkgo.Describe("MCPServer Cross-Replica Session Routing with Redis", fu
374374
redisName = fmt.Sprintf("e2e-redis-%d", ts)
375375

376376
ginkgo.By("Deploying Redis for session storage")
377-
deployRedis(defaultNamespace, redisName, timeout, pollInterval)
377+
deployRedis(redisName)
378378

379379
replicas := int32(2)
380380
redisAddr := fmt.Sprintf("%s.%s.svc.cluster.local:6379", redisName, defaultNamespace)
@@ -413,7 +413,7 @@ var _ = ginkgo.Describe("MCPServer Cross-Replica Session Routing with Redis", fu
413413
_ = k8sClient.Delete(ctx, &mcpv1alpha1.MCPServer{
414414
ObjectMeta: metav1.ObjectMeta{Name: mcpServerName, Namespace: defaultNamespace},
415415
})
416-
cleanupRedis(defaultNamespace, redisName)
416+
cleanupRedis(redisName)
417417

418418
gomega.Eventually(func() bool {
419419
err := k8sClient.Get(ctx, types.NamespacedName{Name: mcpServerName, Namespace: defaultNamespace}, &mcpv1alpha1.MCPServer{})

0 commit comments

Comments
 (0)