Skip to content

Commit

Permalink
Add stats label filter test
Browse files Browse the repository at this point in the history
Adding a conformance test for filtering stats by container labels.

Signed-off-by: Sascha Grunert <[email protected]>
  • Loading branch information
saschagrunert committed Jun 3, 2024
1 parent 31ae1ac commit b3c6d87
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/framework/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,20 @@ func BuildContainerMetadata(containerName string, attempt uint32) *runtimeapi.Co
}
}

// CreateDefaultContainer creates a default container with default options.
// CreateDefaultContainer creates a default container with default options.
func CreateDefaultContainer(rc internalapi.RuntimeService, ic internalapi.ImageManagerService, podID string, podConfig *runtimeapi.PodSandboxConfig, prefix string) string {
return CreateDefaultContainerWithLabels(rc, ic, podID, podConfig, prefix, nil)
}

// CreateDefaultContainerWithLabels creates a default container with default options
func CreateDefaultContainerWithLabels(rc internalapi.RuntimeService, ic internalapi.ImageManagerService, podID string, podConfig *runtimeapi.PodSandboxConfig, prefix string, labels map[string]string) string {
containerName := prefix + NewUUID()
containerConfig := &runtimeapi.ContainerConfig{
Metadata: BuildContainerMetadata(containerName, DefaultAttempt),
Image: &runtimeapi.ImageSpec{Image: TestContext.TestImageList.DefaultTestContainerImage},
Command: DefaultContainerCommand,
Linux: &runtimeapi.LinuxContainerConfig{},
Labels: labels,
}

return CreateContainer(rc, ic, containerConfig, podID, podConfig)
Expand Down
16 changes: 16 additions & 0 deletions pkg/validate/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,22 @@ var _ = framework.KubeDescribe("Container", func() {
Expect(statFound(stats, secondContainerID)).To(BeTrue(), "Stats should be found")
Expect(statFound(stats, thirdContainerID)).To(BeTrue(), "Stats should be found")
})

It("runtime should support listing stats for containers filtered by labels [Conformance]", func() {
By("create container")
labels := map[string]string{"foo": "bar"}
containerID := framework.CreateDefaultContainerWithLabels(rc, ic, podID, podConfig, "container-for-stats-with-labels-", labels)

By("start container")
startContainer(rc, containerID)

By("test container stats")
stats := listContainerStats(rc, &runtimeapi.ContainerStatsFilter{LabelSelector: labels})
Expect(statFound(stats, containerID)).To(BeTrue(), "Container should be found")

stats = listContainerStats(rc, &runtimeapi.ContainerStatsFilter{LabelSelector: map[string]string{"foo": "baz"}})
Expect(statFound(stats, containerID)).To(BeFalse(), "Container should be filtered")
})
})

Context("runtime should support adding volume and device", func() {
Expand Down

0 comments on commit b3c6d87

Please sign in to comment.