Skip to content
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

Translate to tcp probe in queue-proxy when exec probe was used for readinessprobe in user-container #5712

Merged
merged 5 commits into from
Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/reconciler/revision/resources/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ func TestMakePodSpec(t *testing.T) {
withExecReadinessProbe([]string{"echo", "hello"})),
queueContainer(
withEnvVar("CONTAINER_CONCURRENCY", "0"),
withEnvVar("SERVING_READINESS_PROBE", "{}"),
withEnvVar("SERVING_READINESS_PROBE", `{"tcpSocket":{"port":8080,"host":"127.0.0.1"}}`),
),
}),
}, {
Expand Down
7 changes: 6 additions & 1 deletion pkg/reconciler/revision/resources/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,12 @@ func applyReadinessProbeDefaults(p *corev1.Probe, port int32) {
p.TCPSocket.Host = localAddress
p.TCPSocket.Port = intstr.FromInt(int(port))
case p.Exec != nil:
//User-defined ExecProbe will still be run on user-container.
// User-defined ExecProbe will still be run on user-container.
// Use TCP probe in queue-proxy.
p.TCPSocket = &corev1.TCPSocketAction{
Host: localAddress,
Port: intstr.FromInt(int(port)),
}
p.Exec = nil
}

Expand Down
76 changes: 52 additions & 24 deletions test/conformance/runtime/readiness_probe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,65 @@ import (
)

func TestProbeRuntime(t *testing.T) {
t.Parallel()
cancel := logstream.Start(t)
defer cancel()

clients := test.Setup(t)

names := test.ResourceNames{
Service: test.ObjectNameForTest(t),
Image: "runtime",
}
var testCases = []struct {
// name of the test case, which will be inserted in names of routes, configurations, etc.
// Use a short name here to avoid hitting the 63-character limit in names
// (e.g., "service-to-service-call-svc-cluster-local-uagkdshh-frkml-service" is too long.)
name string
// handler to be used for readiness probe in user container.
handler corev1.Handler
}{{
"httpGet",
corev1.Handler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/healthz",
},
},
}, {
"tcpSocket",
corev1.Handler{
TCPSocket: &corev1.TCPSocketAction{},
},
}, {
"exec",
corev1.Handler{
Exec: &corev1.ExecAction{
Command: []string{"/ko-app/runtime", "probe"},
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a case for TCP while you are in here?

I feel like for conformance we should have variants of these tests that FAIL the readiness probes. Could you either add that or open an issue to follow up?

cc @dgerd

Copy link
Contributor

@joshrider joshrider Sep 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've sort of been here before, but the runtime contract suggests that only httpGet and tcpSocket probes should be used. We've quietly left exec probes in, but do we want to codify their allowance into our conformance tests?

},
}}

test.CleanupOnInterrupt(func() { test.TearDown(clients, names) })
defer test.TearDown(clients, names)
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will detach from the logstream, I'd move that in here as part of the change to t.Run

names := test.ResourceNames{
Service: test.ObjectNameForTest(t),
Image: test.Runtime,
}

t.Log("Creating a new Service")
resources, _, err := v1a1test.CreateRunLatestServiceReady(t, clients, &names,
false, /* https TODO(taragu) turn this on after helloworld test running with https */
v1a1opts.WithReadinessProbe(
&corev1.Probe{
Handler: corev1.Handler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/healthz",
},
},
}))
if err != nil {
t.Fatalf("Failed to create initial Service: %v: %v", names.Service, err)
}
test.CleanupOnInterrupt(func() { test.TearDown(clients, names) })
defer test.TearDown(clients, names)

// Check if scaling down works even if access from liveness probe exists.
if err := e2e.WaitForScaleToZero(t, revisionresourcenames.Deployment(resources.Revision), clients); err != nil {
t.Fatalf("Could not scale to zero: %v", err)
t.Log("Creating a new Service")
resources, _, err := v1a1test.CreateRunLatestServiceReady(t, clients, &names,
false, /* https TODO(taragu) turn this on after helloworld test running with https */
v1a1opts.WithReadinessProbe(
&corev1.Probe{
Handler: tc.handler,
}))
if err != nil {
t.Fatalf("Failed to create initial Service: %v: %v", names.Service, err)
}
// Check if scaling down works even if access from liveness probe exists.
if err := e2e.WaitForScaleToZero(t, revisionresourcenames.Deployment(resources.Revision), clients); err != nil {
t.Fatalf("Could not scale to zero: %v", err)
}
})
}
}
13 changes: 12 additions & 1 deletion test/test_images/runtime/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ limitations under the License.
package main

import (
"flag"
"log"
"net/http"
"os"
Expand All @@ -23,14 +24,24 @@ import (
)

func main() {

// We expect PORT to be defined in a Knative environment
// and don't want to mask this failure in a test image.
port, isSet := os.LookupEnv("PORT")
if !isSet {
log.Fatal("Environment variable PORT is not set.")
}

// This is an option for exec readiness probe test.
flag.Parse()
args := flag.Args()
if len(args) > 0 && args[0] == "probe" {
url := "http://localhost:" + port
if _, err := http.Get(url); err != nil {
log.Fatalf("Failed to probe %v", err)
}
return
}

mux := http.NewServeMux()
handlers.InitHandlers(mux)

Expand Down