Skip to content

Commit c1d3397

Browse files
author
Florian Medja
committed
Support exec readiness probes for sidecar containers
1 parent a9c5467 commit c1d3397

File tree

4 files changed

+89
-2
lines changed

4 files changed

+89
-2
lines changed

Diff for: pkg/activator/handler/context.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"context"
2626

2727
"k8s.io/apimachinery/pkg/types"
28+
2829
v1 "knative.dev/serving/pkg/apis/serving/v1"
2930
)
3031

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

53-
// RevIDFrom retrieves the the revisionID from the context.
54+
// RevIDFrom retrieves the revisionID from the context.
5455
func RevIDFrom(ctx context.Context) types.NamespacedName {
5556
return ctx.Value(revCtxKey{}).(*revCtx).revID
5657
}

Diff for: pkg/reconciler/revision/resources/deploy_test.go

+39
Original file line numberDiff line numberDiff line change
@@ -1521,6 +1521,45 @@ func TestMakePodSpec(t *testing.T) {
15211521
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"}}]`),
15221522
),
15231523
}),
1524+
}, {
1525+
name: "with multiple containers with exec probes",
1526+
rev: revision("bar", "foo",
1527+
withContainers([]corev1.Container{{
1528+
Name: servingContainerName,
1529+
Image: "busybox",
1530+
Ports: buildContainerPorts(v1.DefaultUserPort),
1531+
ReadinessProbe: withExecReadinessProbe([]string{"bin/sh", "serving.sh"}),
1532+
}, {
1533+
Name: sidecarContainerName,
1534+
Image: "Ubuntu",
1535+
ReadinessProbe: withExecReadinessProbe([]string{"bin/sh", "sidecar.sh"}),
1536+
}}),
1537+
WithContainerStatuses([]v1.ContainerStatus{{
1538+
ImageDigest: "busybox@sha256:deadbeef",
1539+
}, {
1540+
ImageDigest: "ubuntu@sha256:deadbffe",
1541+
}}),
1542+
),
1543+
fc: apicfg.Features{
1544+
MultiContainerProbing: apicfg.Enabled,
1545+
},
1546+
want: podSpec(
1547+
[]corev1.Container{
1548+
servingContainer(func(container *corev1.Container) {
1549+
container.Image = "busybox@sha256:deadbeef"
1550+
container.ReadinessProbe = withExecReadinessProbe([]string{"bin/sh", "serving.sh"})
1551+
}),
1552+
sidecarContainer(sidecarContainerName,
1553+
func(container *corev1.Container) {
1554+
container.Image = "ubuntu@sha256:deadbffe"
1555+
container.ReadinessProbe = withExecReadinessProbe([]string{"bin/sh", "sidecar.sh"})
1556+
},
1557+
),
1558+
queueContainer(
1559+
withEnvVar("ENABLE_MULTI_CONTAINER_PROBES", "true"),
1560+
withEnvVar("SERVING_READINESS_PROBE", `[{"tcpSocket":{"port":8080,"host":"127.0.0.1"}}]`),
1561+
),
1562+
}),
15241563
}, {
15251564
name: "with default affinity type set",
15261565
rev: revision("bar", "foo",

Diff for: pkg/reconciler/revision/resources/queue.go

+3
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ func makeQueueContainer(rev *v1.Revision, cfg *config.Config) (*corev1.Container
312312
probePort = sc.ReadinessProbe.TCPSocket.Port.IntVal
313313
case sc.ReadinessProbe.GRPC != nil && sc.ReadinessProbe.GRPC.Port > 0:
314314
probePort = sc.ReadinessProbe.GRPC.Port
315+
case sc.ReadinessProbe.Exec != nil:
316+
// Skip the queue-proxy optimization for readiness probing when exec probe is defined on a sidecar container
317+
continue
315318
default:
316319
return nil, fmt.Errorf("sidecar readiness probe does not define probe port on container: %s", sc.Name)
317320
}

Diff for: pkg/reconciler/revision/resources/queue_test.go

+45-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,51 @@ func TestMakeQueueContainer(t *testing.T) {
441441
"ENABLE_MULTI_CONTAINER_PROBES": "true",
442442
})
443443
}),
444-
}}
444+
}, {
445+
name: "multi container probing enabled with exec probes on all containers",
446+
rev: revision("bar", "foo", withContainers([]corev1.Container{
447+
{
448+
Name: servingContainerName,
449+
ReadinessProbe: &corev1.Probe{
450+
ProbeHandler: corev1.ProbeHandler{
451+
Exec: &corev1.ExecAction{
452+
Command: []string{"bin/sh", "serving.sh"},
453+
},
454+
},
455+
},
456+
Ports: []corev1.ContainerPort{{
457+
ContainerPort: 1955,
458+
Name: string(netapi.ProtocolH2C),
459+
}},
460+
},
461+
{
462+
Name: sidecarContainerName,
463+
ReadinessProbe: &corev1.Probe{
464+
ProbeHandler: corev1.ProbeHandler{
465+
Exec: &corev1.ExecAction{
466+
Command: []string{"bin/sh", "sidecar.sh"},
467+
},
468+
},
469+
},
470+
},
471+
})),
472+
fc: apicfg.Features{
473+
MultiContainerProbing: apicfg.Enabled,
474+
},
475+
dc: deployment.Config{
476+
ProgressDeadline: 0 * time.Second,
477+
},
478+
want: queueContainer(func(c *corev1.Container) {
479+
c.Ports = append(queueNonServingPorts, queueHTTP2Port, queueHTTPSPort)
480+
c.ReadinessProbe.ProbeHandler.HTTPGet.Port.IntVal = queueHTTP2Port.ContainerPort
481+
c.Env = env(map[string]string{
482+
"ENABLE_MULTI_CONTAINER_PROBES": "true",
483+
"USER_PORT": "1955",
484+
"QUEUE_SERVING_PORT": "8013",
485+
})
486+
}),
487+
},
488+
}
445489

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

0 commit comments

Comments
 (0)