Skip to content

Commit

Permalink
cni: reduce memory usage (#3047)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzujian committed Jul 18, 2023
1 parent 3be1e84 commit ed58b21
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 18 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build-windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ jobs:
- go.sum
EOF
sh hack/go-list.sh cmd/cni | while read f; do
echo "- $f" | tee -a $filter
done
sh hack/go-list.sh cmd/windows | while read f; do
echo "- $f" | tee -a $filter
done
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,20 @@ ARCH = amd64
.PHONY: build-go
build-go:
go mod tidy
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -buildmode=pie -o $(CURDIR)/dist/images/kube-ovn -ldflags $(GOLDFLAGS) -v ./cmd/cni
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -buildmode=pie -o $(CURDIR)/dist/images/kube-ovn-cmd -ldflags $(GOLDFLAGS) -v ./cmd
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -buildmode=pie -o $(CURDIR)/dist/images/kube-ovn-webhook -ldflags $(GOLDFLAGS) -v ./cmd/webhook
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(CURDIR)/dist/images/test-server -ldflags $(GOLDFLAGS) -v ./test/server

.PHONY: build-go-windows
build-go-windows:
go mod tidy
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -buildmode=pie -o $(CURDIR)/dist/windows/kube-ovn.exe -ldflags $(GOLDFLAGS) -v ./cmd/windows/cni
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -buildmode=pie -o $(CURDIR)/dist/windows/kube-ovn.exe -ldflags $(GOLDFLAGS) -v ./cmd/cni
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -buildmode=pie -o $(CURDIR)/dist/windows/kube-ovn-daemon.exe -ldflags $(GOLDFLAGS) -v ./cmd/windows/daemon

.PHONY: build-go-arm
build-go-arm:
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -buildmode=pie -o $(CURDIR)/dist/images/kube-ovn -ldflags $(GOLDFLAGS) -v ./cmd/cni
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -buildmode=pie -o $(CURDIR)/dist/images/kube-ovn-cmd -ldflags $(GOLDFLAGS) -v ./cmd
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -buildmode=pie -o $(CURDIR)/dist/images/kube-ovn-webhook -ldflags $(GOLDFLAGS) -v ./cmd/webhook

Expand Down
4 changes: 0 additions & 4 deletions cmd/cmdmain.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"os"
"path/filepath"

"github.com/kubeovn/kube-ovn/cmd/cni"
"github.com/kubeovn/kube-ovn/cmd/controller"
"github.com/kubeovn/kube-ovn/cmd/controller_health_check"
"github.com/kubeovn/kube-ovn/cmd/daemon"
Expand All @@ -16,7 +15,6 @@ import (
)

const (
CmdCNI = "kube-ovn"
CmdController = "kube-ovn-controller"
CmdDaemon = "kube-ovn-daemon"
CmdMonitor = "kube-ovn-monitor"
Expand All @@ -29,8 +27,6 @@ const (
func main() {
cmd := filepath.Base(os.Args[0])
switch cmd {
case CmdCNI:
cni.CmdMain()
case CmdController:
controller.CmdMain()
case CmdDaemon:
Expand Down
4 changes: 2 additions & 2 deletions cmd/cni/cni.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cni
package main

import (
"encoding/json"
Expand All @@ -18,7 +18,7 @@ import (
"github.com/kubeovn/kube-ovn/versions"
)

func CmdMain() {
func main() {
// this ensures that main runs only on main thread (thread group leader).
// since namespace ops (unshare, setns) are done for a single thread, we
// must ensure that the goroutine does not jump from OS thread to thread
Expand Down
2 changes: 1 addition & 1 deletion cmd/cni/netconf.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//go:build !windows
// +build !windows

package cni
package main

import (
"github.com/containernetworking/cni/pkg/types"
Expand Down
2 changes: 1 addition & 1 deletion cmd/cni/netconf_windows.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cni
package main

import (
"github.com/containernetworking/plugins/pkg/hns"
Expand Down
7 changes: 0 additions & 7 deletions cmd/windows/cni/main_windows.go

This file was deleted.

4 changes: 2 additions & 2 deletions dist/images/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ RUN rm -f /usr/bin/nc &&\
rm -f /usr/bin/netcat
RUN deluser sync

COPY kube-ovn /kube-ovn/kube-ovn
COPY kube-ovn-cmd /kube-ovn/kube-ovn-cmd
COPY kube-ovn-webhook /kube-ovn/kube-ovn-webhook
RUN ln -s /kube-ovn/kube-ovn-cmd /kube-ovn/kube-ovn && \
ln -s /kube-ovn/kube-ovn-cmd /kube-ovn/kube-ovn-controller && \
RUN ln -s /kube-ovn/kube-ovn-cmd /kube-ovn/kube-ovn-controller && \
ln -s /kube-ovn/kube-ovn-cmd /kube-ovn/kube-ovn-daemon && \
ln -s /kube-ovn/kube-ovn-cmd /kube-ovn/kube-ovn-monitor && \
ln -s /kube-ovn/kube-ovn-cmd /kube-ovn/kube-ovn-pinger && \
Expand Down

0 comments on commit ed58b21

Please sign in to comment.