Skip to content

Commit

Permalink
Trim agent binary by 14mb by conditionally compiled XDS filters (#28670
Browse files Browse the repository at this point in the history
…) (#28718)

* Trim agent binary by 11mb by conditionally compiled XDS filters

Part of #26232

75mb -> 64mb

We could have also done massive refactoring to avoid using build tags,
but I think in the near future we will need build tags for dropping k8s
import, so it seems useful to implement this at least for the short
term.

* Trim another 4mb

(cherry picked from commit 19c8ea4)
  • Loading branch information
howardjohn committed Nov 9, 2020
1 parent c39d9db commit 1f69a56
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
25 changes: 15 additions & 10 deletions Makefile.core.mk
Expand Up @@ -262,10 +262,15 @@ fmt: format-go format-python tidy-go
buildcache:
GOBUILDFLAGS=-i $(MAKE) -e -f Makefile.core.mk build

# gobuild script uses custom linker flag to set the variables.
RELEASE_LDFLAGS='-extldflags -static -s -w'

# List of all binaries to build
BINARIES:=./istioctl/cmd/istioctl \
# We split the binaries into "agent" binaries and standard ones. This corresponds to build "agent".
# This allows conditional compilation to avoid pulling in costly dependencies to the agent, such as XDS and k8s.
AGENT_BINARIES:=./pilot/cmd/pilot-agent
STANDARD_BINARIES:=./istioctl/cmd/istioctl \
./pilot/cmd/pilot-discovery \
./pilot/cmd/pilot-agent \
./pkg/test/echo/cmd/client \
./pkg/test/echo/cmd/server \
./operator/cmd/operator \
Expand All @@ -275,21 +280,24 @@ BINARIES:=./istioctl/cmd/istioctl \
./cni/cmd/install-cni \
./tools/istio-iptables \
./tools/bug-report
BINARIES:=$(STANDARD_BINARIES) $(AGENT_BINARIES)

# List of binaries included in releases
RELEASE_BINARIES:=pilot-discovery pilot-agent istioctl bug-report

.PHONY: build
build: depend ## Builds all go binaries.
STATIC=0 GOOS=$(GOOS_LOCAL) GOARCH=$(GOARCH_LOCAL) LDFLAGS=$(RELEASE_LDFLAGS) common/scripts/gobuild.sh $(ISTIO_OUT)/ $(BINARIES)
STATIC=0 GOOS=$(GOOS_LOCAL) GOARCH=$(GOARCH_LOCAL) LDFLAGS=$(RELEASE_LDFLAGS) common/scripts/gobuild.sh $(ISTIO_OUT)/ $(STANDARD_BINARIES)
GOOS=$(GOOS_LOCAL) GOARCH=$(GOARCH_LOCAL) LDFLAGS=$(RELEASE_LDFLAGS) common/scripts/gobuild.sh $(ISTIO_OUT)/ -tags=agent $(AGENT_BINARIES)

# The build-linux target is responsible for building binaries used within containers.
# This target should be expanded upon as we add more Linux architectures: i.e. build-arm64.
# Then a new build target can be created such as build-container-bin that builds these
# various platform images.
.PHONY: build-linux
build-linux: depend
STATIC=0 GOOS=linux GOARCH=$(GOARCH_LOCAL) LDFLAGS=$(RELEASE_LDFLAGS) common/scripts/gobuild.sh $(ISTIO_OUT_LINUX)/ $(BINARIES)
STATIC=0 GOOS=linux GOARCH=$(GOARCH_LOCAL) LDFLAGS=$(RELEASE_LDFLAGS) common/scripts/gobuild.sh $(ISTIO_OUT_LINUX)/ $(STANDARD_BINARIES)
GOOS=linux GOARCH=$(GOARCH_LOCAL) LDFLAGS=$(RELEASE_LDFLAGS) common/scripts/gobuild.sh $(ISTIO_OUT_LINUX)/ -tags=agent $(AGENT_BINARIES)

# Create targets for ISTIO_OUT_LINUX/binary
# There are two use cases here:
Expand All @@ -302,11 +310,12 @@ ifeq ($(BUILD_ALL),true)
$(ISTIO_OUT_LINUX)/$(shell basename $(1)): build-linux
else
$(ISTIO_OUT_LINUX)/$(shell basename $(1)): $(ISTIO_OUT_LINUX)
STATIC=0 GOOS=linux GOARCH=$(GOARCH_LOCAL) LDFLAGS=$(RELEASE_LDFLAGS) common/scripts/gobuild.sh $(ISTIO_OUT_LINUX)/ $(1)
STATIC=0 GOOS=linux GOARCH=$(GOARCH_LOCAL) LDFLAGS=$(RELEASE_LDFLAGS) common/scripts/gobuild.sh $(ISTIO_OUT_LINUX)/ -tags=$(2) $(1)
endif
endef

$(foreach bin,$(BINARIES),$(eval $(call build-linux,$(bin))))
$(foreach bin,$(STANDARD_BINARIES),$(eval $(call build-linux,$(bin),"")))
$(foreach bin,$(AGENT_BINARIES),$(eval $(call build-linux,$(bin),"agent")))

# Create helper targets for each binary, like "pilot-discovery"
# As an optimization, these still build everything
Expand Down Expand Up @@ -368,10 +377,6 @@ gen-kustomize:
# Target: go build
#-----------------------------------------------------------------------------

# gobuild script uses custom linker flag to set the variables.

RELEASE_LDFLAGS='-extldflags -static -s -w'

# Non-static istioctl targets. These are typically a build artifact.
${ISTIO_OUT}/release/istioctl-linux-amd64: depend
STATIC=0 GOOS=linux GOARCH=amd64 LDFLAGS=$(RELEASE_LDFLAGS) common/scripts/gobuild.sh $@ ./istioctl/cmd/istioctl
Expand Down
4 changes: 1 addition & 3 deletions pilot/pkg/xds/v2/model.go
Expand Up @@ -14,9 +14,7 @@

package v2

import "github.com/envoyproxy/go-control-plane/pkg/resource/v2"

const (
// EndpointType is used for EDS and ADS endpoint discovery. Typically second request.
EndpointType = resource.EndpointType
EndpointType = "type.googleapis.com/envoy.api.v2.ClusterLoadAssignment"
)
1 change: 1 addition & 0 deletions pkg/config/xds/filter_types.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pkg/config/xds/filter_types.go
Expand Up @@ -12,7 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:generate sh -c "echo '// Copyright Istio Authors' > filter_types.gen.go"
//go:generate sh -c "echo '// +build !agent' > filter_types.gen.go"
//go:generate sh -c "echo '// Copyright Istio Authors' >> filter_types.gen.go"
//go:generate sh -c "echo '//' >> filter_types.gen.go"
//go:generate sh -c "echo '// Licensed under the Apache License, Version 2.0 (the \"License\");' >> filter_types.gen.go"
//go:generate sh -c "echo '// you may not use this file except in compliance with the License.' >> filter_types.gen.go"
Expand Down

0 comments on commit 1f69a56

Please sign in to comment.