Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #39

Merged
merged 5 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ build: ## build the Gostwire stripped static binary
build-embedded: ## build the Gostwire stripped static binary with embedded web UI
@$(GENAPIDOC)
( \
$(GETGITVERSION) \
cd webui \
REACT_APP_GIT_VERSION=$$GIT_VERSION yarn build \
$(GETGITVERSION) && \
cd webui && \
echo "$$GIT_VERSION" && \
sed -i "s/^VITE_REACT_APP_GIT_VERSION=.*/VITE_REACT_APP_GIT_VERSION=$$GIT_VERSION/" .env && \
yarn build \
)
go build -v $(GOSTATIC),webui ./cmd/gostwire
@file gostwire
Expand All @@ -80,7 +82,7 @@ deploy: ## deploy Gostwire service exposed on host port 5999
&& echo "deploying version" $$GIT_VERSION \
&& scripts/docker-build.sh deployments/gostwire/Dockerfile \
-t gostwire \
--build-arg GIT_VERSION=$$GIT_VERSION \
--build-arg REACT_APP_GIT_VERSION=$$GIT_VERSION \
--build-context webappsrc=./webui \
)
docker compose -p gostwire -f deployments/gostwire/docker-compose.yaml up
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
![goroutines](https://img.shields.io/badge/go%20routines-not%20leaking-success)
![file descriptors](https://img.shields.io/badge/file%20descriptors-not%20leaking-success)
[![Go Report Card](https://goreportcard.com/badge/github.com/siemens/ghostwire/v2)](https://goreportcard.com/report/github.com/siemens/ghostwire/v2)
![Coverage](https://img.shields.io/badge/Coverage-76.2%25-yellow)
![Coverage](https://img.shields.io/badge/Coverage-72.6%25-yellow)

**G(h)ostwire** discovers the virtual (or not) network configuration inside
_Linux_ hosts – and can be deployed as a REST service or consumed as a Go
Expand Down
26 changes: 16 additions & 10 deletions api/v1/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,18 @@ func Decorate(engines []*model.ContainerEngine, labels map[string]string) {
}

func tabulaRasa() {
nerdctl.NerdctlIgnore("rm", "-f", podc1)
nerdctl.NerdctlIgnore("rm", "-f", podc2)
nerdctl.NerdctlIgnore("rm", "-f", bareName)
nerdctl.NerdctlIgnore("network", "rm", podNetworkName)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
nerdctl.NerdctlIgnore(ctx, "rm", "-f", podc1)
nerdctl.NerdctlIgnore(ctx, "rm", "-f", podc2)
nerdctl.NerdctlIgnore(ctx, "rm", "-f", bareName)
nerdctl.NerdctlIgnore(ctx, "network", "rm", podNetworkName)
}

var v1apispec *openapi3.T
var disco gostwire.DiscoveryResult

var _ = BeforeSuite(func() {
var _ = BeforeSuite(func(ctx context.Context) {
if os.Getuid() != 0 {
return
}
Expand All @@ -124,20 +126,24 @@ var _ = BeforeSuite(func() {
tabulaRasa()

By("setting up some fake pod containers")
nerdctl.Nerdctl("network", "create", podNetworkName)
nerdctl.Nerdctl(
cmdctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
nerdctl.Nerdctl(cmdctx, "network", "create", podNetworkName)
cmdctx, cancel = context.WithTimeout(ctx, 60*time.Second)
defer cancel()
nerdctl.Nerdctl(cmdctx,
"run", "-d",
"--name", bareName,
"busybox", "/bin/sleep", "120s")
nerdctl.Nerdctl(
nerdctl.Nerdctl(cmdctx,
"run", "-d",
"--name", podc1,
"--network", podNetworkName,
"--label", kuhbernetes.PodNamespaceLabel+"="+podNamespace,
"--label", kuhbernetes.PodNameLabel+"="+podName,
"--label", kuhbernetes.PodContainerNameLabel+"="+podc1,
"busybox", "/bin/sleep", "120s")
nerdctl.Nerdctl(
nerdctl.Nerdctl(cmdctx,
"run", "-d",
"--name", podc2,
"--network", podNetworkName,
Expand All @@ -147,7 +153,7 @@ var _ = BeforeSuite(func() {
"busybox", "/bin/sleep", "120s")

By("discovering")
ctx, cancel := context.WithCancel(context.Background())
ctx, cancel = context.WithCancel(ctx)
cizer := turtlefinder.New(func() context.Context { return ctx })
defer cancel()
defer cizer.Close()
Expand Down
2 changes: 1 addition & 1 deletion cmd/gostwire/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
// dynVarsRe matches the window.dynvars assignment, so we can rewrite (or
// rather, insert) the current values of variables that might or might not
// changed based on the particular HTTP request.
var dynVarsRe = regexp.MustCompile(`(<script>window\.dynvars=){}(</script>)`)
var dynVarsRe = regexp.MustCompile(`(<script>window\.dynvars\s*=\s*){}(\s*</script>)`)

var (
once sync.Once
Expand Down
24 changes: 16 additions & 8 deletions decorator/nerdctlnet/nerdctlnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,17 @@ var _ = Describe("nerdctlnet decorator", func() {
goodfds := Filedescriptors()
goodgos := Goroutines() // avoid other failed goroutine tests to spill over

nerdctl.NerdctlIgnore("rm", "-f", testWorkloadName)
nerdctl.NerdctlIgnore("network", "rm", testNetworkName)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
nerdctl.NerdctlIgnore(ctx, "rm", "-f", testWorkloadName)
nerdctl.NerdctlIgnore(ctx, "network", "rm", testNetworkName)

DeferCleanup(func() {
gexec.KillAndWait()
nerdctl.NerdctlIgnore("rm", "-f", testWorkloadName)
nerdctl.NerdctlIgnore("network", "rm", testNetworkName)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
nerdctl.NerdctlIgnore(ctx, "rm", "-f", testWorkloadName)
nerdctl.NerdctlIgnore(ctx, "network", "rm", testNetworkName)

Eventually(Goroutines).WithTimeout(2 * time.Second).WithPolling(250 * time.Millisecond).
ShouldNot(HaveLeaked(goodgos))
Expand All @@ -65,18 +69,22 @@ var _ = Describe("nerdctlnet decorator", func() {
nerdctl.SkipWithout()

By(fmt.Sprintf("creating a test bridge network %q", testNetworkName))
nerdctl.Nerdctl("network", "create", "--label=foo=bar", testNetworkName)
cmdctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
nerdctl.Nerdctl(cmdctx, "network", "create", "--label=foo=bar", testNetworkName)

By("creating a test workload and connecting it to the test network")
nerdctl.NerdctlIgnore("rm", "-f", testWorkloadName)
nerdctl.Nerdctl(
cmdctx, cancel = context.WithTimeout(ctx, 60*time.Second)
defer cancel()
nerdctl.NerdctlIgnore(cmdctx, "rm", "-f", testWorkloadName)
nerdctl.Nerdctl(cmdctx,
"run", "-d",
"--name", testWorkloadName,
"--network", testNetworkName,
"busybox", "/bin/sleep", "120s")

By("running a discovery")
ctx, cancel := context.WithCancel(ctx)
ctx, cancel = context.WithCancel(ctx)
cizer := turtlefinder.New(func() context.Context { return ctx })
defer cancel()
defer cizer.Close()
Expand Down
3 changes: 2 additions & 1 deletion deployments/gostwire/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ RUN yarn eslint --init
COPY --from=webappsrc public/ ./public/
COPY --from=webappsrc src/ ./src/
COPY --from=webappsrc .env ./
ARG GIT_VERSION
ARG REACT_APP_GIT_VERSION
RUN sed -i "s/^VITE_REACT_APP_GIT_VERSION=.*/VITE_REACT_APP_GIT_VERSION=${REACT_APP_GIT_VERSION}/" .env
RUN yarn build

# -- 3. stage ---------------------------------------------------------------
Expand Down
15 changes: 10 additions & 5 deletions test/nerdctl/nerdctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
package nerdctl

import (
"context"
"os/exec"
"time"

"github.com/onsi/gomega/gexec"

Expand All @@ -15,26 +17,29 @@ import (

// Nerdctl runs a nerdctl command with the specified CLI arguments, expecting
// the command to succeed without any error code.
func Nerdctl(args ...string) {
func Nerdctl(ctx context.Context, args ...string) {
gi.GinkgoHelper()
session, err := gexec.Start(
exec.Command("nerdctl", args...),
gi.GinkgoWriter,
gi.GinkgoWriter)
g.ExpectWithOffset(1, err).NotTo(g.HaveOccurred())
g.EventuallyWithOffset(1, session, "5s").Should(gexec.Exit(0))
g.Expect(err).NotTo(g.HaveOccurred())
g.Eventually(ctx, session).ProbeEvery(100 * time.Millisecond).
Should(gexec.Exit(0))
}

// NerdctlIgnore runs a nerdctl command with the specified CLI arguments and
// ignores whatever outcome of running the nerdctl command will be.
func NerdctlIgnore(args ...string) {
func NerdctlIgnore(ctx context.Context, args ...string) {
gi.GinkgoHelper()
session, err := gexec.Start(
exec.Command("nerdctl", args...),
gi.GinkgoWriter,
gi.GinkgoWriter)
if err != nil {
return
}
g.EventuallyWithOffset(1, session, "5s").Should(gexec.Exit())
g.Eventually(ctx, session).Should(gexec.Exit())
}

// SkipWithout skips a test if nerdctl cannot be found in PATH.
Expand Down
2 changes: 1 addition & 1 deletion webui/.env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VITE_REACT_APP_GIT_VERSION=$REACT_APP_GIT_VERSION
VITE_REACT_APP_GIT_VERSION=2.3.0-3-g190b76b
4 changes: 2 additions & 2 deletions webui/src/views/about/About.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# <BrandIcon style={{width: 'auto', height: '2.5ex', verticalAlign: 'middle'}}/> <Brand/>

© Siemens 2018-2023. All rights reserved.
© Siemens 2018-2024. All rights reserved.

## In a Nutshell

Expand All @@ -13,7 +13,7 @@ Please see also our integrated detailed <a href="/help/gw">help</a>.

## App Information

- **web app version:** <span children={import.meta.env.REACT_APP_GIT_VERSION}/>
- **web app version:** <span children={import.meta.env.VITE_REACT_APP_GIT_VERSION}/>

- **discovery backend engine:** <DiscoveryMetadata />

Expand Down
2 changes: 1 addition & 1 deletion webui/src/views/help/chapters/Ghostwire.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ install this plugin at any time without the need to restart your browser
## Copyright

The [Edgeshark project](https://github.com/siemens/edgeshark) is (c) Siemens
2023 and available under the MIT license.
2023, 2024 and available under the MIT license.

## Trademarks

Expand Down
Loading