Skip to content

Commit

Permalink
Support exec readiness probes for sidecar containers
Browse files Browse the repository at this point in the history
  • Loading branch information
FloMedja authored and Florian Medja committed Feb 12, 2025
1 parent a9c5467 commit c14663c
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pkg/activator/handler/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"context"

"k8s.io/apimachinery/pkg/types"

v1 "knative.dev/serving/pkg/apis/serving/v1"
)

Expand All @@ -50,7 +51,7 @@ func RevisionFrom(ctx context.Context) *v1.Revision {
return ctx.Value(revCtxKey{}).(*revCtx).revision
}

// RevIDFrom retrieves the the revisionID from the context.
// RevIDFrom retrieves the revisionID from the context.
func RevIDFrom(ctx context.Context) types.NamespacedName {
return ctx.Value(revCtxKey{}).(*revCtx).revID
}
Expand Down
39 changes: 39 additions & 0 deletions pkg/reconciler/revision/resources/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1521,6 +1521,45 @@ func TestMakePodSpec(t *testing.T) {
withEnvVar("SERVING_READINESS_PROBE", `[{"httpGet":{"path":"/","port":8080,"host":"127.0.0.1","scheme":"HTTP"}},{"httpGet":{"path":"/","port":8090,"host":"127.0.0.1","scheme":"HTTP"}}]`),
),
}),
}, {
name: "with multiple containers with exec probes",
rev: revision("bar", "foo",
withContainers([]corev1.Container{{
Name: servingContainerName,
Image: "busybox",
Ports: buildContainerPorts(v1.DefaultUserPort),
ReadinessProbe: withExecReadinessProbe([]string{"bin/sh", "serving.sh"}),
}, {
Name: sidecarContainerName,
Image: "Ubuntu",
ReadinessProbe: withExecReadinessProbe([]string{"bin/sh", "sidecar.sh"}),
}}),
WithContainerStatuses([]v1.ContainerStatus{{
ImageDigest: "busybox@sha256:deadbeef",
}, {
ImageDigest: "ubuntu@sha256:deadbffe",
}}),
),
fc: apicfg.Features{
MultiContainerProbing: apicfg.Enabled,
},
want: podSpec(
[]corev1.Container{
servingContainer(func(container *corev1.Container) {
container.Image = "busybox@sha256:deadbeef"
container.ReadinessProbe = withExecReadinessProbe([]string{"bin/sh", "serving.sh"})
}),
sidecarContainer(sidecarContainerName,
func(container *corev1.Container) {
container.Image = "ubuntu@sha256:deadbffe"
container.ReadinessProbe = withExecReadinessProbe([]string{"bin/sh", "sidecar.sh"})
},
),
queueContainer(
withEnvVar("ENABLE_MULTI_CONTAINER_PROBES", "true"),
withEnvVar("SERVING_READINESS_PROBE", `[{"tcpSocket":{"port":8080,"host":"127.0.0.1"}}]`),
),
}),
}, {
name: "with default affinity type set",
rev: revision("bar", "foo",
Expand Down
3 changes: 3 additions & 0 deletions pkg/reconciler/revision/resources/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ func makeQueueContainer(rev *v1.Revision, cfg *config.Config) (*corev1.Container
probePort = sc.ReadinessProbe.TCPSocket.Port.IntVal
case sc.ReadinessProbe.GRPC != nil && sc.ReadinessProbe.GRPC.Port > 0:
probePort = sc.ReadinessProbe.GRPC.Port
case sc.ReadinessProbe.Exec != nil:
// Skip the queue-proxy optimization for readiness probing when exec probe is defined on a sidecar container
continue
default:
return nil, fmt.Errorf("sidecar readiness probe does not define probe port on container: %s", sc.Name)
}
Expand Down
46 changes: 45 additions & 1 deletion pkg/reconciler/revision/resources/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,51 @@ func TestMakeQueueContainer(t *testing.T) {
"ENABLE_MULTI_CONTAINER_PROBES": "true",
})
}),
}}
}, {
name: "multi container probing enabled with exec probes on all containers",
rev: revision("bar", "foo", withContainers([]corev1.Container{
{
Name: servingContainerName,
ReadinessProbe: &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
Exec: &corev1.ExecAction{
Command: []string{"bin/sh", "serving.sh"},
},
},
},
Ports: []corev1.ContainerPort{{
ContainerPort: 1955,
Name: string(netapi.ProtocolH2C),
}},
},
{
Name: sidecarContainerName,
ReadinessProbe: &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
Exec: &corev1.ExecAction{
Command: []string{"bin/sh", "sidecar.sh"},
},
},
},
},
})),
fc: apicfg.Features{
MultiContainerProbing: apicfg.Enabled,
},
dc: deployment.Config{
ProgressDeadline: 0 * time.Second,
},
want: queueContainer(func(c *corev1.Container) {
c.Ports = append(queueNonServingPorts, queueHTTP2Port, queueHTTPSPort)
c.ReadinessProbe.ProbeHandler.HTTPGet.Port.IntVal = queueHTTP2Port.ContainerPort
c.Env = env(map[string]string{
"ENABLE_MULTI_CONTAINER_PROBES": "true",
"USER_PORT": "1955",
"QUEUE_SERVING_PORT": "8013",
})
}),
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
Expand Down

0 comments on commit c14663c

Please sign in to comment.