From 6aacc311d5ffc72e477478a14c735f3da251d596 Mon Sep 17 00:00:00 2001 From: thediveo Date: Thu, 18 Jan 2024 12:46:58 +0100 Subject: [PATCH] chore: refactoring Signed-off-by: thediveo --- decorator/dockernet/dockernet.go | 4 ---- decorator/podmannet/libpodclient.go | 7 +++++++ decorator/podmannet/podmannet.go | 4 ---- defs_version.go | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/decorator/dockernet/dockernet.go b/decorator/dockernet/dockernet.go index 2a4c0cb..b274b13 100644 --- a/decorator/dockernet/dockernet.go +++ b/decorator/dockernet/dockernet.go @@ -8,7 +8,6 @@ import ( "context" "fmt" "strings" - "time" "github.com/siemens/ghostwire/v2/decorator" "github.com/siemens/ghostwire/v2/network" @@ -70,7 +69,6 @@ type dockerNetworks struct { func makeDockerNetworks(ctx context.Context, engine *model.ContainerEngine, allnetns network.NetworkNamespaces) ( docknets dockerNetworks, ) { - start := time.Now() dockerclient, err := client.NewClientWithOpts( client.WithHost(engine.API), client.WithAPIVersionNegotiation()) @@ -81,8 +79,6 @@ func makeDockerNetworks(ctx context.Context, engine *model.ContainerEngine, alln } networks, _ := dockerclient.NetworkList(ctx, types.NetworkListOptions{}) _ = dockerclient.Close() - span := time.Since(start) - log.Debugf("docker(%d) network ls took %s", engine.PID, span) netnsid, _ := ops.NamespacePath(fmt.Sprintf("/proc/%d/ns/net", engine.PID)).ID() docknets.networks = networks docknets.engine = engine diff --git a/decorator/podmannet/libpodclient.go b/decorator/podmannet/libpodclient.go index 9b0ecf7..0f790d4 100644 --- a/decorator/podmannet/libpodclient.go +++ b/decorator/podmannet/libpodclient.go @@ -121,6 +121,13 @@ func ensureReaderClosed(resp *http.Response) { resp.Body.Close() } +// ping the /_ping API endpoint (which is unversioned) and return the value of +// the “Libpod-Api-Version” header that came back from this endpoint, or an +// empty string. The libpod API version is in semver format, without any “v” +// prefix. +// +// Use the returned API version to set Client.libpodVersion so that following +// libpod endpoint calls are properly versioned. func (c *Client) ping(ctx context.Context) (libpodAPIVersion string) { resp, err := c.get(ctx, "/_ping") defer ensureReaderClosed(resp) diff --git a/decorator/podmannet/podmannet.go b/decorator/podmannet/podmannet.go index 54fb30a..f604792 100644 --- a/decorator/podmannet/podmannet.go +++ b/decorator/podmannet/podmannet.go @@ -7,7 +7,6 @@ package podmannet import ( "context" "fmt" - "time" "github.com/siemens/ghostwire/v2/decorator" "github.com/siemens/ghostwire/v2/decorator/dockernet" @@ -48,7 +47,6 @@ type podmanNetworks struct { func makePodmanNetworks(ctx context.Context, engine *model.ContainerEngine, allnetns network.NetworkNamespaces) ( podmannets podmanNetworks, ) { - start := time.Now() libpodclient, err := newLibpodClient(engine.API) if err != nil { log.Warnf("cannot discover podman-managed networks from API %s, reason: %s", @@ -58,8 +56,6 @@ func makePodmanNetworks(ctx context.Context, engine *model.ContainerEngine, alln libpodclient.libpodVersion = libpodclient.ping(ctx) networks, _ := libpodclient.networkList(ctx) _ = libpodclient.Close() - span := time.Since(start) - log.Debugf("podman(%d) network ls took %s", engine.PID, span) netnsid, _ := ops.NamespacePath(fmt.Sprintf("/proc/%d/ns/net", engine.PID)).ID() podmannets.networks = networks podmannets.engine = engine diff --git a/defs_version.go b/defs_version.go index 843e2b9..c6109bc 100644 --- a/defs_version.go +++ b/defs_version.go @@ -4,4 +4,4 @@ package gostwire // SemVersion is the semantic version string of the ghostwire module. -const SemVersion = "2.1.18-12-gede2f48" +const SemVersion = "2.3.0-4-g1927622"