diff --git a/backend/controller/scaling/kube_scaling_integration_test.go b/backend/controller/scaling/kube_scaling_integration_test.go index ca32955686..fcd6e09729 100644 --- a/backend/controller/scaling/kube_scaling_integration_test.go +++ b/backend/controller/scaling/kube_scaling_integration_test.go @@ -5,6 +5,7 @@ package scaling_test import ( "context" "fmt" + "strconv" "strings" "sync" "testing" @@ -31,13 +32,31 @@ func runKubeScalingTest(t *testing.T, istio bool) { done.Store(false) routineStopped := sync.WaitGroup{} routineStopped.Add(1) + echoDeployment := map[string]string{} in.Run(t, in.WithIstio(istio), in.CopyModule("echo"), in.Deploy("echo"), + in.CopyModule("naughty"), + in.Deploy("naughty"), in.Call("echo", "echo", "Bob", func(t testing.TB, response string) { assert.Equal(t, "Hello, Bob!!!", response) }), + in.VerifyKubeState(func(ctx context.Context, t testing.TB, namespace string, client *kubernetes.Clientset) { + deps, err := client.AppsV1().Deployments(namespace).List(ctx, v1.ListOptions{}) + assert.NoError(t, err) + for _, dep := range deps.Items { + if strings.HasPrefix(dep.Name, "dpl-echo") { + echoDeployment["name"] = dep.Name + } + } + assert.NotEqual(t, "", echoDeployment["name"]) + }), + in.Call("naughty", "beNaughty", echoDeployment, func(t testing.TB, response string) { + // If istio is not present we should be able to ping the echo service directly. + // Istio should prevent this + assert.Equal(t, strconv.FormatBool(!istio), response) + }), in.EditFile("echo", func(content []byte) []byte { return []byte(strings.ReplaceAll(string(content), "Hello", "Bye")) }, "echo.go"), @@ -70,7 +89,7 @@ func runKubeScalingTest(t *testing.T, istio bool) { assert.NoError(t, err) depCount := 0 for _, dep := range deps.Items { - if strings.HasPrefix(dep.Name, "dpl-echo") || strings.HasPrefix(dep.Name, "dpl-time") { + if strings.HasPrefix(dep.Name, "dpl-echo") { depCount++ service, err := client.CoreV1().Services(namespace).Get(ctx, dep.Name, v1.GetOptions{}) assert.NoError(t, err) diff --git a/backend/controller/scaling/testdata/go/naughty/ftl.toml b/backend/controller/scaling/testdata/go/naughty/ftl.toml new file mode 100644 index 0000000000..3b3e40728a --- /dev/null +++ b/backend/controller/scaling/testdata/go/naughty/ftl.toml @@ -0,0 +1,2 @@ +module = "naughty" +language = "go" diff --git a/backend/controller/scaling/testdata/go/naughty/go.mod b/backend/controller/scaling/testdata/go/naughty/go.mod new file mode 100644 index 0000000000..f19778ed2f --- /dev/null +++ b/backend/controller/scaling/testdata/go/naughty/go.mod @@ -0,0 +1,8 @@ +module ftl/naughty + +go 1.23.0 + +replace ( + github.com/TBD54566975/ftl => ./../../../../../.. + +) diff --git a/backend/controller/scaling/testdata/go/naughty/go.sum b/backend/controller/scaling/testdata/go/naughty/go.sum new file mode 100644 index 0000000000..e69de29bb2 diff --git a/backend/controller/scaling/testdata/go/naughty/naughty.go b/backend/controller/scaling/testdata/go/naughty/naughty.go new file mode 100644 index 0000000000..400592a288 --- /dev/null +++ b/backend/controller/scaling/testdata/go/naughty/naughty.go @@ -0,0 +1,29 @@ +// This is the echo module. +package naughty + +import ( + "context" + "fmt" + "io" + "net/http" + "strconv" +) + +// BeNaughty attempts to ping echo directly and returns true if successful +// +//ftl:verb export +func BeNaughty(ctx context.Context, endpoint map[string]string) (string, error) { + url := "http://" + endpoint["name"] + ":8893/healthz" // Replace with your actual URL + + resp, err := http.Get(url) + if err != nil { + return fmt.Sprintf("Error making GET request: to %s %v\n", url, err), nil + } + defer resp.Body.Close() + + _, err = io.ReadAll(resp.Body) + if err != nil { + return fmt.Sprintf("Error reading response body: %v\n", err), nil + } + return strconv.FormatBool(resp.StatusCode == 200), nil +}