Skip to content

Commit

Permalink
Remove go run from all go generate commands
Browse files Browse the repository at this point in the history
Including `go run` in the //go:generate pragmas is never really how `go
generate` was intended to be used. While it's a seemingly-useful hack to
pin versions of tools, it breaks cross-compilation.

Cross-compilation breaks because if the requested GOARCH differs from
the one `go generate` is being run on, `go run` receives the same GOARCH
and builds the tool for that platform instead. The tool will never exec
correctly because of the platform mismatch.

This removes `go run` from all `//go:generate` pragmas and adds the
appropriate installation of these tools to the Dockerfile. Developers
are expected to have these tools installed in the same way in their
development environment (in the same way as go, clang, etc.).
  • Loading branch information
timraymond committed Nov 21, 2024
1 parent 5e11f6f commit 436581a
Show file tree
Hide file tree
Showing 25 changed files with 26 additions and 24 deletions.
2 changes: 2 additions & 0 deletions controller/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ ENV GOOS=${GOOS}
RUN if [ "$GOOS" = "linux" ] ; then \
tdnf install -y clang16 lld16 bpftool libbpf-devel; \
fi
RUN go install github.com/cilium/ebpf/cmd/[email protected]; \
go install go.uber.org/mock/[email protected]
COPY ./pkg/plugin /go/src/github.com/microsoft/retina/pkg/plugin
WORKDIR /go/src/github.com/microsoft/retina
RUN if [ "$GOOS" = "linux" ] ; then \
Expand Down
2 changes: 1 addition & 1 deletion pkg/capture/provider/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/microsoft/retina/pkg/capture/file"
)

//go:generate go run go.uber.org/mock/mockgen@v0.4.0 -source=interface.go -destination=mock_network_capture.go -package=provider Interface
//go:generate mockgen -source=interface.go -destination=mock_network_capture.go -package=provider Interface
type NetworkCaptureProviderInterface interface {
// Setup prepares the provider with folder to store network capture for temporary.
Setup(filename file.CaptureFilename) (string, error)
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/cache/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/microsoft/retina/pkg/common"
)

//go:generate go run go.uber.org/mock/mockgen@v0.4.0 -destination=mock_cacheinterface.go -copyright_file=../../lib/ignore_headers.txt -package=cache github.com/microsoft/retina/pkg/controllers/cache CacheInterface
//go:generate mockgen -destination=mock_cacheinterface.go -copyright_file=../../lib/ignore_headers.txt -package=cache github.com/microsoft/retina/pkg/controllers/cache CacheInterface
type CacheInterface interface {
// GetPodByIP returns the retina endpoint for the given IP.
GetPodByIP(ip string) *common.RetinaEndpoint
Expand Down
2 changes: 1 addition & 1 deletion pkg/enricher/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/cilium/cilium/pkg/hubble/container"
)

//go:generate go run go.uber.org/mock/mockgen@v0.4.0 -destination=mock_enricherinterface.go -copyright_file=../lib/ignore_headers.txt -package=enricher github.com/microsoft/retina/pkg/enricher EnricherInterface
//go:generate mockgen -destination=mock_enricherinterface.go -copyright_file=../lib/ignore_headers.txt -package=enricher github.com/microsoft/retina/pkg/enricher EnricherInterface

type EnricherInterface interface {
Run()
Expand Down
2 changes: 1 addition & 1 deletion pkg/hubble/common/decoder_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/cilium/cilium/pkg/labels"
)

//go:generate go run github.com/golang/mock/mockgen@v1.6.0 -source decoder.go -destination=mocks/mock_types.go -package=mocks
//go:generate mockgen -source decoder.go -destination=mocks/mock_types.go -package=mocks

type EpDecoder interface {
Decode(ip netip.Addr) *flow.Endpoint
Expand Down
2 changes: 1 addition & 1 deletion pkg/managers/filtermanager/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net"
)

//go:generate go run go.uber.org/mock/mockgen@v0.4.0 -source=types.go -destination=mock_types.go -package=filtermanager
//go:generate mockgen -source=types.go -destination=mock_types.go -package=filtermanager
type ICache interface {
ips() []net.IP
reset()
Expand Down
2 changes: 1 addition & 1 deletion pkg/managers/watchermanager/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/microsoft/retina/pkg/log"
)

//go:generate go run go.uber.org/mock/mockgen@v0.4.0 -source=types.go -destination=mocks/mock_types.go -package=mocks .
//go:generate mockgen -source=types.go -destination=mocks/mock_types.go -package=mocks .
type IWatcher interface {
// Init, Stop, and Refresh should only be called by watchermanager.
Init(ctx context.Context) error
Expand Down
2 changes: 1 addition & 1 deletion pkg/metrics/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
dto "github.com/prometheus/client_model/go"
)

//go:generate go run go.uber.org/mock/mockgen@v0.4.0 -source=interfaces.go -destination=mock_types.go -package=metrics
//go:generate mockgen -source=interfaces.go -destination=mock_types.go -package=metrics

type CounterVec interface {
WithLabelValues(lvs ...string) prometheus.Counter
Expand Down
2 changes: 1 addition & 1 deletion pkg/module/metrics/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const (
egress = "egress"
)

//go:generate go run go.uber.org/mock/mockgen@v0.4.0 -source=types.go -destination=mock_types.go -package=metrics
//go:generate mockgen -source=types.go -destination=mock_types.go -package=metrics
type IModule interface {
Reconcile(spec *api.MetricsSpec) error
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/module/traces/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package traces

import api "github.com/microsoft/retina/crd/api/v1alpha1"

//go:generate go run go.uber.org/mock/mockgen@v0.4.0 -destination=mock_moduleinterface.go -copyright_file=../../lib/ignore_headers.txt -package=traces github.com/microsoft/retina/pkg/module/traces ModuleInterface
//go:generate mockgen -destination=mock_moduleinterface.go -copyright_file=../../lib/ignore_headers.txt -package=traces github.com/microsoft/retina/pkg/module/traces ModuleInterface

type ModuleInterface interface {
// Run starts the trace module.
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
v1 "github.com/cilium/cilium/pkg/hubble/api/v1"
)

//go:generate go run go.uber.org/mock/mockgen@v0.4.0 -destination=mock/mock_plugin.go -copyright_file=../../lib/ignore_headers.txt -package=mock github.com/microsoft/retina/pkg/plugin/api Plugin
//go:generate mockgen -destination=mock/mock_plugin.go -copyright_file=../../lib/ignore_headers.txt -package=mock github.com/microsoft/retina/pkg/plugin/api Plugin

const (
Meter string = "retina-meter"
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/common/common_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"golang.org/x/sys/unix"
)

//go:generate go run go.uber.org/mock/mockgen@v0.4.0 -destination=mocks/mock_types.go -package=mocks . ITracer
//go:generate mockgen -destination=mocks/mock_types.go -package=mocks . ITracer

// Interface for IG tracers.
// Ref: https://pkg.go.dev/github.com/inspektor-gadget/[email protected]/pkg/gadgets/trace/dns/tracer#Tracer
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/conntrack/conntrack_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"go.uber.org/zap"
)

//go:generate go run github.com/cilium/ebpf/cmd/bpf2go@master -cflags "-g -O2 -Wall -D__TARGET_ARCH_${GOARCH} -Wall" -target ${GOARCH} -type ct_v4_key conntrack ./_cprog/conntrack.c -- -I../lib/_${GOARCH} -I../lib/common/libbpf/_src -I../lib/common/libbpf/_include/linux -I../lib/common/libbpf/_include/uapi/linux -I../lib/common/libbpf/_include/asm
//go:generate bpf2go -cflags "-g -O2 -Wall -D__TARGET_ARCH_${GOARCH} -Wall" -target ${GOARCH} -type ct_v4_key conntrack ./_cprog/conntrack.c -- -I../lib/_${GOARCH} -I../lib/common/libbpf/_src -I../lib/common/libbpf/_include/linux -I../lib/common/libbpf/_include/uapi/linux -I../lib/common/libbpf/_include/asm

// Init initializes the conntrack eBPF map in the kernel for the first time.
// This function should be called in the init container since
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/dropreason/dropreason_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"go.uber.org/zap"
)

//go:generate go run github.com/cilium/ebpf/cmd/bpf2go@master -cflags "-g -O2 -Wall -D__TARGET_ARCH_${GOARCH} -Wall" -target ${GOARCH} -type metrics_map_value -type drop_reason_t -type packet kprobe ./_cprog/drop_reason.c -- -I../lib/_${GOARCH} -I../lib/common/libbpf/_src -I../filter/_cprog/
//go:generate bpf2go -cflags "-g -O2 -Wall -D__TARGET_ARCH_${GOARCH} -Wall" -target ${GOARCH} -type metrics_map_value -type drop_reason_t -type packet kprobe ./_cprog/drop_reason.c -- -I../lib/_${GOARCH} -I../lib/common/libbpf/_src -I../filter/_cprog/
const (
nfHookSlowFn = "nf_hook_slow"
tcpConnectFn = "tcp_v4_connect"
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/dropreason/types_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type (
// Interface to https://pkg.go.dev/github.com/cilium/ebpf#Map.
// Added for unit tests.
//
//go:generate go run go.uber.org/mock/mockgen@v0.4.0 -source=types_linux.go -destination=mocks/mock_types.go -package=dropreason . IMap IMapIterator IPerfReader
//go:generate mockgen -source=types_linux.go -destination=mocks/mock_types.go -package=dropreason . IMap IMapIterator IPerfReader
type IMapIterator interface {
Next(keyOut interface{}, valueOut interface{}) bool
Err() error
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/filter/filter_map_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
_ "github.com/microsoft/retina/pkg/plugin/filter/_cprog" // nolint
)

//go:generate go run github.com/cilium/ebpf/cmd/bpf2go@master -cflags "-g -O2 -Wall -D__TARGET_ARCH_${GOARCH} -Wall" -target ${GOARCH} -type mapKey filter ./_cprog/retina_filter.c -- -I../lib/_${GOARCH} -I../lib/common/libbpf/_src
//go:generate bpf2go -cflags "-g -O2 -Wall -D__TARGET_ARCH_${GOARCH} -Wall" -target ${GOARCH} -type mapKey filter ./_cprog/retina_filter.c -- -I../lib/_${GOARCH} -I../lib/common/libbpf/_src

var (
f *FilterMap
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/filter/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/cilium/ebpf"
)

//go:generate go run go.uber.org/mock/mockgen@v0.4.0 -source=types.go -destination=mocks/mock_types.go -package=mocks
//go:generate mockgen -source=types.go -destination=mocks/mock_types.go -package=mocks

/*
A thin wrapper around the eBPF map that allows adding and deleting IPv4 addresses.
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/infiniband/types_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const (
Name api.PluginName = "infiniband"
)

//go:generate go run go.uber.org/mock/mockgen@v0.4.0 -source=types_linux.go -destination=infiniband_mock_generated.go -package=infiniband
//go:generate mockgen -source=types_linux.go -destination=infiniband_mock_generated.go -package=infiniband
type infiniband struct {
cfg *kcfg.Config
l *log.ZapLogger
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/linuxutil/types_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const (
Name api.PluginName = "linuxutil"
)

//go:generate go run go.uber.org/mock/mockgen@v0.4.0 -source=types_linux.go -destination=linuxutil_mock_generated.go -package=linuxutil
//go:generate mockgen -source=types_linux.go -destination=linuxutil_mock_generated.go -package=linuxutil
type linuxUtil struct {
cfg *kcfg.Config
l *log.ZapLogger
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/packetforward/packetforward_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
_ "github.com/microsoft/retina/pkg/plugin/packetforward/_cprog" // nolint
)

//go:generate go run github.com/cilium/ebpf/cmd/bpf2go@master -cflags "-g -O2 -Wall -D__TARGET_ARCH_${GOARCH} -Wall" -target ${GOARCH} -type metric packetforward ./_cprog/packetforward.c -- -I../lib/_${GOARCH} -I../lib/common/libbpf/_src
//go:generate bpf2go -cflags "-g -O2 -Wall -D__TARGET_ARCH_${GOARCH} -Wall" -target ${GOARCH} -type metric packetforward ./_cprog/packetforward.c -- -I../lib/_${GOARCH} -I../lib/common/libbpf/_src

// New creates a new packetforward plugin.
func New(cfg *kcfg.Config) api.Plugin {
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/packetforward/types_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const (
// Interface to https://pkg.go.dev/github.com/cilium/ebpf#Map.
// Added for unit tests.
//
//go:generate go run go.uber.org/mock/mockgen@v0.4.0 -destination=mocks/mock_types.go -package=mocks . IMap
//go:generate mockgen -destination=mocks/mock_types.go -package=mocks . IMap
type IMap interface {
Lookup(key, valueOut interface{}) error
Close() error
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/packetparser/packetparser_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import (
"golang.org/x/sys/unix"
)

//go:generate go run github.com/cilium/ebpf/cmd/bpf2go@master -cflags "-g -O2 -Wall -D__TARGET_ARCH_${GOARCH} -Wall" -target ${GOARCH} -type packet packetparser ./_cprog/packetparser.c -- -I../lib/_${GOARCH} -I../lib/common/libbpf/_src -I../lib/common/libbpf/_include/linux -I../lib/common/libbpf/_include/uapi/linux -I../lib/common/libbpf/_include/asm -I../filter/_cprog/ -I../conntrack/_cprog/
//go:generate bpf2go -cflags "-g -O2 -Wall -D__TARGET_ARCH_${GOARCH} -Wall" -target ${GOARCH} -type packet packetparser ./_cprog/packetparser.c -- -I../lib/_${GOARCH} -I../lib/common/libbpf/_src -I../lib/common/libbpf/_include/linux -I../lib/common/libbpf/_include/uapi/linux -I../lib/common/libbpf/_include/asm -I../filter/_cprog/ -I../conntrack/_cprog/
var errNoOutgoingLinks = errors.New("could not determine any outgoing links")

// New creates a packetparser plugin.
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/packetparser/types_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ type tcValue struct {
qdisc *tc.Object
}

//go:generate go run go.uber.org/mock/mockgen@v0.4.0 -source=types_linux.go -destination=mocks/mock_types.go -package=mocks
//go:generate mockgen -source=types_linux.go -destination=mocks/mock_types.go -package=mocks

// tc qdisc interface
type qdisc interface {
Expand Down
2 changes: 1 addition & 1 deletion pkg/pubsub/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package pubsub

type CallBackFunc func(interface{})

//go:generate go run go.uber.org/mock/mockgen@v0.4.0 -destination=mock_pubsubinterface.go -copyright_file=../lib/ignore_headers.txt -package=pubsub github.com/microsoft/retina/pkg/pubsub PubSubInterface
//go:generate mockgen -destination=mock_pubsubinterface.go -copyright_file=../lib/ignore_headers.txt -package=pubsub github.com/microsoft/retina/pkg/pubsub PubSubInterface

// this file defines the interface a simple pubsub implementation should implement
type PubSubInterface interface {
Expand Down
2 changes: 1 addition & 1 deletion pkg/watchers/apiserver/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package apiserver

import "context"

//go:generate go run go.uber.org/mock/mockgen@v0.4.0 -source=types.go -destination=mocks/mock_types.go -package=mocks .
//go:generate mockgen -source=types.go -destination=mocks/mock_types.go -package=mocks .
type IHostResolver interface {
LookupHost(context context.Context, host string) ([]string, error)
}
Expand Down

0 comments on commit 436581a

Please sign in to comment.