Skip to content

Commit

Permalink
chore: reduce binary size
Browse files Browse the repository at this point in the history
  • Loading branch information
oilbeater committed Dec 9, 2020
1 parent ce25b26 commit 9738af1
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 32 deletions.
13 changes: 2 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,11 @@ push-dev:

build-go:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(PWD)/dist/images/kube-ovn -ldflags $(GOLDFLAGS) -v ./cmd/cni
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(PWD)/dist/images/kube-ovn-controller -ldflags $(GOLDFLAGS) -v ./cmd/controller
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(PWD)/dist/images/kube-ovn-daemon -ldflags $(GOLDFLAGS) -v ./cmd/daemon
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(PWD)/dist/images/kube-ovn-pinger -ldflags $(GOLDFLAGS) -v ./cmd/pinger
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(PWD)/dist/images/kube-ovn-monitor -ldflags $(GOLDFLAGS) -v ./cmd/ovn_monitor
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(PWD)/dist/images/kube-ovn-speaker -ldflags $(GOLDFLAGS) -v ./cmd/speaker

CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(PWD)/dist/images/kube-ovn-cmd -ldflags $(GOLDFLAGS) -v ./cmd

build-go-arm:
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o $(PWD)/dist/images/kube-ovn -ldflags $(GOLDFLAGS) -v ./cmd/cni
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o $(PWD)/dist/images/kube-ovn-controller -ldflags $(GOLDFLAGS) -v ./cmd/controller
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o $(PWD)/dist/images/kube-ovn-daemon -ldflags $(GOLDFLAGS) -v ./cmd/daemon
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o $(PWD)/dist/images/kube-ovn-pinger -ldflags $(GOLDFLAGS) -v ./cmd/pinger
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o $(PWD)/dist/images/kube-ovn-monitor -ldflags $(GOLDFLAGS) -v ./cmd/ovn_monitor
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o $(PWD)/dist/images/kube-ovn-speaker -ldflags $(GOLDFLAGS) -v ./cmd/speaker
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o $(PWD)/dist/images/kube-ovn-cmd -ldflags $(GOLDFLAGS) -v ./cmd

release: lint build-go
docker buildx build --cache-from "type=local,src=/tmp/.buildx-cache" --cache-to "type=local,dest=/tmp/.buildx-cache" --platform linux/amd64 --build-arg ARCH=amd64 --build-arg RPM_ARCH=x86_64 -t ${REGISTRY}/kube-ovn:${RELEASE_TAG} -o type=docker -f dist/images/Dockerfile dist/images/
Expand Down
39 changes: 39 additions & 0 deletions cmd/cmdmain.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package main

import (
"github.com/alauda/kube-ovn/cmd/controller"
"github.com/alauda/kube-ovn/cmd/daemon"
"github.com/alauda/kube-ovn/cmd/ovn_monitor"
"github.com/alauda/kube-ovn/cmd/pinger"
"github.com/alauda/kube-ovn/cmd/speaker"
"k8s.io/klog"
"os"
"strings"
)

const (
CmdController = "kube-ovn-controller"
CmdDaemon = "kube-ovn-daemon"
CmdMonitor = "kube-ovn-monitor"
CmdPinger = "kube-ovn-pinger"
CmdSpeaker = "kube-ovn-speaker"
)

func main() {
cmds := strings.Split(os.Args[0], "/")
cmd := cmds[len(cmds)-1]
switch cmd {
case CmdController:
controller.CmdMain()
case CmdDaemon:
daemon.CmdMain()
case CmdMonitor:
ovn_monitor.CmdMain()
case CmdPinger:
pinger.CmdMain()
case CmdSpeaker:
speaker.CmdMain()
default:
klog.Fatalf("%s is an unknown command", cmd)
}
}
6 changes: 4 additions & 2 deletions cmd/controller/controller.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package controller

import (
"fmt"
Expand All @@ -16,12 +16,14 @@ import (
"k8s.io/sample-controller/pkg/signals"
)

func main() {
func CmdMain() {
defer klog.Flush()

stopCh := signals.SetupSignalHandler()
klog.Infof(versions.String())

controller.InitClientGoMetrics()
controller.InitWorkQueueMetrics()
config, err := controller.ParseFlags()
if err != nil {
klog.Fatalf("parse config failed %v", err)
Expand Down
5 changes: 3 additions & 2 deletions cmd/daemon/cniserver.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package daemon

import (
"fmt"
Expand All @@ -17,10 +17,11 @@ import (
"k8s.io/sample-controller/pkg/signals"
)

func main() {
func CmdMain() {
defer klog.Flush()

klog.Infof(versions.String())
daemon.InitMetrics()
config, err := daemon.ParseFlags()
if err != nil {
klog.Fatalf("parse config failed %v", err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/ovn_monitor/ovn_monitor.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package ovn_monitor

import (
"github.com/alauda/kube-ovn/versions"
Expand All @@ -9,7 +9,7 @@ import (
"k8s.io/klog"
)

func main() {
func CmdMain() {
defer klog.Flush()

klog.Infof(versions.String())
Expand Down
5 changes: 3 additions & 2 deletions cmd/pinger/pinger.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package pinger

import (
"fmt"
Expand All @@ -10,10 +10,11 @@ import (
"k8s.io/klog"
)

func main() {
func CmdMain() {
defer klog.Flush()

klog.Infof(versions.String())
pinger.InitPingerMetrics()
config, err := pinger.ParseFlags()
if err != nil {
klog.Fatalf("parse config failed %v", err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/speaker/speaker.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package speaker

import (
"fmt"
Expand All @@ -10,7 +10,7 @@ import (
"net/http"
)

func main() {
func CmdMain() {
defer klog.Flush()

klog.Infof(versions.String())
Expand Down
14 changes: 7 additions & 7 deletions dist/images/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ RUN --mount=type=bind,target=/rpms,from=ovs-rpm,source=/rpms rpm -ivh --nodeps /
COPY *.sh /kube-ovn/
COPY grace_stop_ovn_controller /usr/share/ovn/scripts/grace_stop_ovn_controller
COPY 01-kube-ovn.conflist /kube-ovn/01-kube-ovn.conflist
RUN rpm -e --nodeps sqlite-libs

WORKDIR /kube-ovn

RUN rpm -e --nodeps sqlite-libs
COPY kube-ovn-pinger /kube-ovn/kube-ovn-pinger
COPY kube-ovn /kube-ovn/kube-ovn
COPY kube-ovn-daemon /kube-ovn/kube-ovn-daemon
COPY kube-ovn-controller /kube-ovn/kube-ovn-controller
COPY kube-ovn-monitor /kube-ovn/kube-ovn-monitor
COPY kube-ovn-speaker /kube-ovn/kube-ovn-speaker
COPY kube-ovn-cmd /kube-ovn/kube-ovn-cmd
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 && \
ln -s /kube-ovn/kube-ovn-cmd /kube-ovn/kube-ovn-speaker
2 changes: 1 addition & 1 deletion pkg/controller/client_go_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ var (
}, []string{"name"})
)

func init() {
func InitClientGoMetrics() {
registerClientMetrics()
registerReflectorMetrics()
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/workqueue_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
// which registers metrics to the default prometheus Registry. We require very
// similar functionality, but must register metrics to a different Registry.

func init() {
func InitWorkQueueMetrics() {
workqueue.SetProvider(workqueueMetricsProvider{})
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/daemon/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ var (
}, []string{"name"})
)

func init() {
func InitMetrics() {
registerReflectorMetrics()
registerClientMetrics()
prometheus.MustRegister(cniOperationHistogram)
Expand Down
2 changes: 1 addition & 1 deletion pkg/pinger/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ var (
})
)

func init() {
func InitPingerMetrics() {
prometheus.MustRegister(ovsUpGauge)
prometheus.MustRegister(ovsDownGauge)
prometheus.MustRegister(ovnControllerUpGauge)
Expand Down

0 comments on commit 9738af1

Please sign in to comment.