Skip to content

Commit

Permalink
fix: api unit test relying on deprecated decorator
Browse files Browse the repository at this point in the history
Signed-off-by: thediveo <[email protected]>
  • Loading branch information
thediveo committed Dec 5, 2023
1 parent c2fb889 commit c0f20a1
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions api/v1/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import (
"github.com/siemens/ghostwire/v2/test/nerdctl"
"github.com/siemens/ghostwire/v2/util"
"github.com/siemens/turtlefinder"
"github.com/thediveo/go-plugger/v3"
"github.com/thediveo/lxkns/decorator"
"github.com/thediveo/lxkns/decorator/kuhbernetes"
"github.com/thediveo/lxkns/model"
"github.com/thediveo/whalewatcher/watcher/containerd"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -41,6 +45,56 @@ func TestGostwireApiV1(t *testing.T) {
RunSpecs(t, "ghostwire/api/v1 package")
}

// Register testing pod grouping plugin.
func init() {
plugger.Group[decorator.Decorate]().Register(
Decorate, plugger.WithPlugin("kuhtainerd"))
}

// PodDecorate decorates the discovered containerd containers with pod groups,
// where applicable. This used to be in general use until the advent of the CRI
// API-based watcher and its generic decoration; now we use it to avoid having
// to rewrite the whole test here.
func Decorate(engines []*model.ContainerEngine, labels map[string]string) {
total := 0
for _, engine := range engines {
// If it "ain't no" containerd, skip it, as we're looking specifically
// for containerd engines and their particular Kubernetes pod labelling.
if engine.Type != containerd.Type {
continue
}
// Pods cannot span container engines ;)
podgroups := map[string]*model.Group{}
for _, container := range engine.Containers {
podNamespace := container.Labels[kuhbernetes.PodNamespaceLabel]
podName := container.Labels[kuhbernetes.PodNameLabel]
if podName == "" || podNamespace == "" {
continue
}
// Create a new pod group, if it doesn't exist yet. Add the
// container to its pod group.
namespacedpodname := podNamespace + "/" + podName
podgroup, ok := podgroups[namespacedpodname]
if !ok {
podgroup = &model.Group{
Name: namespacedpodname,
Type: kuhbernetes.PodGroupType,
Flavor: kuhbernetes.PodGroupType,
}
podgroups[namespacedpodname] = podgroup
total++
}
podgroup.AddContainer(container)
// Sandbox? Then tag (label) the container.
/*
if container.Labels[containerKindLabel] == "sandbox" {
container.Labels[kuhbernetes.PodSandboxLabel] = ""
}
*/
}
}
}

func tabulaRasa() {
nerdctl.NerdctlIgnore("rm", "-f", podc1)
nerdctl.NerdctlIgnore("rm", "-f", podc2)
Expand Down

0 comments on commit c0f20a1

Please sign in to comment.