lakitu: Upgrade containerd to 1.4.1.

As part of the upgrade, we remove the Go cross-compiler patch and
replace it with an exported shell function that calls the
cross-compiler. The Go cross-compiler patch is hard to maintain and is
error-prone. The logs show that the exported shell function is being
used correctly by the Makefile.

BUG=b/168846654
TEST=presubmit
RELEASE_NOTE=Upgraded containerd to version 1.4.1.

Change-Id: Ic86e20a647b1b2dc1ef09d09be1752a6b1068fb4
diff --git a/overlay-lakitu/app-emulation/containerd/Manifest b/overlay-lakitu/app-emulation/containerd/Manifest
index d4e41a5..033d234 100644
--- a/overlay-lakitu/app-emulation/containerd/Manifest
+++ b/overlay-lakitu/app-emulation/containerd/Manifest
@@ -1 +1 @@
-DIST containerd-1.4.0.tar.gz 6165201 BLAKE2B d90d03fea9992827ac31e3b438d1891d50103c01387d4b5e66506ad72509e3f0ca97ca096384ec76843fc49c49684e139107914db486f3ec1aae023ceb5dd2cc SHA512 5ac733a0823f5b680d40f76cb5a8277e84efdd6642d15c1735049f8859bf9f87b212b4075bdc13e8f09a5564b55ce74d7d1290628b0ca92d9753ef9bfa9a0e44
+DIST containerd-1.4.1.tar.gz 6168048 BLAKE2B f050808d77c66caead8acba595b1cf91d7f386a77aae84d08840f458ba8141bb0e8763222f37b4295d2afedd5eb2fc311e8a69f6c01a08740ad27d2e7380b61f SHA512 e16196db59ba71cfd7e5515b8d2bc6336503e996419182274dfc5ac9caca901cf712f465698e9ff667747959faf93cdf66fe652c47a83a6ead6f6a3a22add43b
diff --git a/overlay-lakitu/app-emulation/containerd/containerd-1.4.0-r2.ebuild b/overlay-lakitu/app-emulation/containerd/containerd-1.4.0-r2.ebuild
deleted file mode 120000
index 8578240..0000000
--- a/overlay-lakitu/app-emulation/containerd/containerd-1.4.0-r2.ebuild
+++ /dev/null
@@ -1 +0,0 @@
-containerd-1.4.0.ebuild
\ No newline at end of file
diff --git a/overlay-lakitu/app-emulation/containerd/containerd-1.4.1-r1.ebuild b/overlay-lakitu/app-emulation/containerd/containerd-1.4.1-r1.ebuild
new file mode 120000
index 0000000..7fed344
--- /dev/null
+++ b/overlay-lakitu/app-emulation/containerd/containerd-1.4.1-r1.ebuild
@@ -0,0 +1 @@
+containerd-1.4.1.ebuild
\ No newline at end of file
diff --git a/overlay-lakitu/app-emulation/containerd/containerd-1.4.0.ebuild b/overlay-lakitu/app-emulation/containerd/containerd-1.4.1.ebuild
similarity index 79%
rename from overlay-lakitu/app-emulation/containerd/containerd-1.4.0.ebuild
rename to overlay-lakitu/app-emulation/containerd/containerd-1.4.1.ebuild
index 890c840..8cb1241 100644
--- a/overlay-lakitu/app-emulation/containerd/containerd-1.4.0.ebuild
+++ b/overlay-lakitu/app-emulation/containerd/containerd-1.4.1.ebuild
@@ -12,7 +12,7 @@
 else
 	MY_PV="${PV/_rc/-rc.}"
 	EGIT_COMMIT="v${MY_PV}"
-	CONTAINERD_COMMIT="09814d48d50816305a8e6c1a4ae3e2bcc4ba725a"
+	CONTAINERD_COMMIT="c623d1b36f09f8ef6536a057bd658b3aa8632828"
 	SRC_URI="https://${EGO_PN}/archive/${EGIT_COMMIT}.tar.gz -> ${P}.tar.gz"
 	KEYWORDS="*"
 	inherit golang-vcs-snapshot
@@ -37,17 +37,11 @@
 S=${WORKDIR}/${P}/src/${EGO_PN}
 
 PATCHES=(
-	# lakitu: uses Go cross compiler in the builder (i.e. ${GO}) rather than
-	# the default go compiler in the builders (i.e. go).
-	"${FILESDIR}"/1.4.0-Read-the-Go-tool-to-use-from-the-environment.patch
 	# lakitu: three changes in containerd.service:
 	# 1. always restart containerd
 	# 2. set containerd path to /usr/bin/containerd
 	# 3. set OOM score to -999
 	"${FILESDIR}"/1.4.0-customize-containerd-service.patch
-	# lakitu: added a patch to downgrade the shim process and
-	# consume logs. remove it after the next upgrade
-	"${FILESDIR}"/consume_shim_logs_and_downgrade_shim_process.patch
 )
 
 RESTRICT="test"
@@ -65,11 +59,18 @@
 src_compile() {
 	local options=( $(usex btrfs "" "no_btrfs") $(usex cri "" "no_cri") $(usex seccomp "seccomp" "") $(usex apparmor "apparmor" "") )
 	export GOPATH="${WORKDIR}/${P}" # ${PWD}/vendor
-	# lakitu: create environment variable ${GO} to point to the Go cross
-	# compiler.
+	# lakitu: export a function named 'go' that invokes the go cross-compiler.
+	# The containerd Makefile will invoke this function instead of doing a PATH
+	# lookup for the go binary.
 	GO=$(tc-getGO)
 	export GO
+	go() {
+		echo "${GO} $@"
+		"${GO}" "$@"
+	}
+	export -f go
 	LDFLAGS=$(usex hardened '-extldflags -fno-PIC' '') BUILDTAGS="${options[@]}" emake
+	unset -f go
 }
 
 src_install() {
diff --git a/overlay-lakitu/app-emulation/containerd/files/1.4.0-Read-the-Go-tool-to-use-from-the-environment.patch b/overlay-lakitu/app-emulation/containerd/files/1.4.0-Read-the-Go-tool-to-use-from-the-environment.patch
deleted file mode 100644
index 1e22c0e..0000000
--- a/overlay-lakitu/app-emulation/containerd/files/1.4.0-Read-the-Go-tool-to-use-from-the-environment.patch
+++ /dev/null
@@ -1,144 +0,0 @@
-From c0b8b443576b8a369870e425262c456e1c3a58c5 Mon Sep 17 00:00:00 2001
-From: Robert Kolchmeyer <rkolchmeyer@google.com>
-Date: Wed, 1 Jul 2020 13:56:06 -0700
-Subject: [PATCH 1/2] Read the Go tool to use from the environment.
-
-We need to pass in the ChromeOS cross compiler.
----
- Makefile | 42 +++++++++++++++++++++---------------------
- 1 file changed, 21 insertions(+), 21 deletions(-)
-
-diff --git a/Makefile b/Makefile
-index f2592adf..9febd026 100644
---- a/Makefile
-+++ b/Makefile
-@@ -25,9 +25,9 @@ REVISION=$(shell git rev-parse HEAD)$(shell if ! git diff --no-ext-diff --quiet
- PACKAGE=github.com/containerd/containerd
- SHIM_CGO_ENABLED ?= 0
- 
--ifneq "$(strip $(shell command -v go 2>/dev/null))" ""
--	GOOS ?= $(shell go env GOOS)
--	GOARCH ?= $(shell go env GOARCH)
-+ifneq "$(strip $(shell command -v ${GO} 2>/dev/null))" ""
-+	GOOS ?= $(shell ${GO} env GOOS)
-+	GOARCH ?= $(shell ${GO} env GOARCH)
- else
- 	ifeq ($(GOOS),)
- 		# approximate GOOS for the platform if we don't have Go and GOOS isn't
-@@ -69,7 +69,7 @@ RELEASE=containerd-$(VERSION:v%=%).${GOOS}-${GOARCH}
- PKG=github.com/containerd/containerd
- 
- # Project packages.
--PACKAGES=$(shell go list ./... | grep -v /vendor/)
-+PACKAGES=$(shell ${GO} list ./... | grep -v /vendor/)
- INTEGRATION_PACKAGE=${PKG}
- TEST_REQUIRES_ROOT_PACKAGES=$(filter \
-     ${PACKAGES}, \
-@@ -136,7 +136,7 @@ AUTHORS: .mailmap .git/HEAD
- 
- generate: protos
- 	@echo "$(WHALE) $@"
--	@PATH="${ROOTDIR}/bin:${PATH}" go generate -x ${PACKAGES}
-+	@PATH="${ROOTDIR}/bin:${PATH}" ${GO} generate -x ${PACKAGES}
- 
- protos: bin/protoc-gen-gogoctrd ## generate protobuf
- 	@echo "$(WHALE) $@"
-@@ -161,31 +161,31 @@ proto-fmt: ## check format of proto files
- 	@test -z "$$(find . -path ./vendor -prune -o -name '*.proto' -type f -exec grep -Hn "Meta meta = " {} \; | grep -v '(gogoproto.nullable) = false' | tee /dev/stderr)" || \
- 		(echo "$(ONI) meta fields in proto files must have option (gogoproto.nullable) = false" && false)
- 
--build: ## build the go packages
-+build: ## build the ${GO} packages
- 	@echo "$(WHALE) $@"
--	@go build ${DEBUG_GO_GCFLAGS} ${GO_GCFLAGS} ${GO_BUILD_FLAGS} ${EXTRA_FLAGS} ${GO_LDFLAGS} ${PACKAGES}
-+	@${GO} build ${DEBUG_GO_GCFLAGS} ${GO_GCFLAGS} ${GO_BUILD_FLAGS} ${EXTRA_FLAGS} ${GO_LDFLAGS} ${PACKAGES}
- 
- test: ## run tests, except integration tests and tests that require root
- 	@echo "$(WHALE) $@"
--	@go test ${TESTFLAGS} $(filter-out ${INTEGRATION_PACKAGE},${PACKAGES})
-+	@${GO} test ${TESTFLAGS} $(filter-out ${INTEGRATION_PACKAGE},${PACKAGES})
- 
- root-test: ## run tests, except integration tests
- 	@echo "$(WHALE) $@"
--	@go test ${TESTFLAGS} $(filter-out ${INTEGRATION_PACKAGE},${TEST_REQUIRES_ROOT_PACKAGES}) -test.root
-+	@${GO} test ${TESTFLAGS} $(filter-out ${INTEGRATION_PACKAGE},${TEST_REQUIRES_ROOT_PACKAGES}) -test.root
- 
- integration: ## run integration tests
- 	@echo "$(WHALE) $@"
--	@go test ${TESTFLAGS} -test.root -parallel ${TESTFLAGS_PARALLEL}
-+	@${GO} test ${TESTFLAGS} -test.root -parallel ${TESTFLAGS_PARALLEL}
- 
- benchmark: ## run benchmarks tests
- 	@echo "$(WHALE) $@"
--	@go test ${TESTFLAGS} -bench . -run Benchmark -test.root
-+	@${GO} test ${TESTFLAGS} -bench . -run Benchmark -test.root
- 
- FORCE:
- 
- define BUILD_BINARY =
- @echo "$(WHALE) $@"
--@go build ${DEBUG_GO_GCFLAGS} ${GO_GCFLAGS} ${GO_BUILD_FLAGS} -o $@ ${GO_LDFLAGS} ${GO_TAGS}  ./$<
-+@${GO} build ${DEBUG_GO_GCFLAGS} ${GO_GCFLAGS} ${GO_BUILD_FLAGS} -o $@ ${GO_LDFLAGS} ${GO_TAGS}  ./$<
- endef
- 
- # Build a binary from a cmd.
-@@ -194,15 +194,15 @@ bin/%: cmd/% FORCE
- 
- bin/containerd-shim: cmd/containerd-shim FORCE # set !cgo and omit pie for a static shim build: https://github.com/golang/go/issues/17789#issuecomment-258542220
- 	@echo "$(WHALE) bin/containerd-shim"
--	@CGO_ENABLED=${SHIM_CGO_ENABLED} go build ${GO_BUILD_FLAGS} -o bin/containerd-shim ${SHIM_GO_LDFLAGS} ${GO_TAGS} ./cmd/containerd-shim
-+	@CGO_ENABLED=${SHIM_CGO_ENABLED} ${GO} build ${GO_BUILD_FLAGS} -o bin/containerd-shim ${SHIM_GO_LDFLAGS} ${GO_TAGS} ./cmd/containerd-shim
- 
- bin/containerd-shim-runc-v1: cmd/containerd-shim-runc-v1 FORCE # set !cgo and omit pie for a static shim build: https://github.com/golang/go/issues/17789#issuecomment-258542220
- 	@echo "$(WHALE) bin/containerd-shim-runc-v1"
--	@CGO_ENABLED=${SHIM_CGO_ENABLED} go build ${GO_BUILD_FLAGS} -o bin/containerd-shim-runc-v1 ${SHIM_GO_LDFLAGS} ${GO_TAGS} ./cmd/containerd-shim-runc-v1
-+	@CGO_ENABLED=${SHIM_CGO_ENABLED} ${GO} build ${GO_BUILD_FLAGS} -o bin/containerd-shim-runc-v1 ${SHIM_GO_LDFLAGS} ${GO_TAGS} ./cmd/containerd-shim-runc-v1
- 
- bin/containerd-shim-runc-v2: cmd/containerd-shim-runc-v2 FORCE # set !cgo and omit pie for a static shim build: https://github.com/golang/go/issues/17789#issuecomment-258542220
- 	@echo "$(WHALE) bin/containerd-shim-runc-v2"
--	@CGO_ENABLED=${SHIM_CGO_ENABLED} go build ${GO_BUILD_FLAGS} -o bin/containerd-shim-runc-v2 ${SHIM_GO_LDFLAGS} ${GO_TAGS} ./cmd/containerd-shim-runc-v2
-+	@CGO_ENABLED=${SHIM_CGO_ENABLED} ${GO} build ${GO_BUILD_FLAGS} -o bin/containerd-shim-runc-v2 ${SHIM_GO_LDFLAGS} ${GO_TAGS} ./cmd/containerd-shim-runc-v2
- 
- binaries: $(BINARIES) ## build binaries
- 	@echo "$(WHALE) $@"
-@@ -218,11 +218,11 @@ genman: man/containerd.8 man/ctr.8
- 
- man/containerd.8: FORCE
- 	@echo "$(WHALE) $@"
--	go run cmd/gen-manpages/main.go $(@F) $(@D)
-+	${GO} run cmd/gen-manpages/main.go $(@F) $(@D)
- 
- man/ctr.8: FORCE
- 	@echo "$(WHALE) $@"
--	go run cmd/gen-manpages/main.go $(@F) $(@D)
-+	${GO} run cmd/gen-manpages/main.go $(@F) $(@D)
- 
- man/%: docs/man/%.md FORCE
- 	@echo "$(WHALE) $@"
-@@ -284,9 +284,9 @@ uninstall:
- coverage: ## generate coverprofiles from the unit tests, except tests that require root
- 	@echo "$(WHALE) $@"
- 	@rm -f coverage.txt
--	@go test -i ${TESTFLAGS} $(filter-out ${INTEGRATION_PACKAGE},${PACKAGES}) 2> /dev/null
-+	@${GO} test -i ${TESTFLAGS} $(filter-out ${INTEGRATION_PACKAGE},${PACKAGES}) 2> /dev/null
- 	@( for pkg in $(filter-out ${INTEGRATION_PACKAGE},${PACKAGES}); do \
--		go test ${TESTFLAGS} \
-+		${GO} test ${TESTFLAGS} \
- 			-cover \
- 			-coverprofile=profile.out \
- 			-covermode=atomic $$pkg || exit; \
-@@ -298,9 +298,9 @@ coverage: ## generate coverprofiles from the unit tests, except tests that requi
- 
- root-coverage: ## generate coverage profiles for unit tests that require root
- 	@echo "$(WHALE) $@"
--	@go test -i ${TESTFLAGS} $(filter-out ${INTEGRATION_PACKAGE},${TEST_REQUIRES_ROOT_PACKAGES}) 2> /dev/null
-+	@${GO} test -i ${TESTFLAGS} $(filter-out ${INTEGRATION_PACKAGE},${TEST_REQUIRES_ROOT_PACKAGES}) 2> /dev/null
- 	@( for pkg in $(filter-out ${INTEGRATION_PACKAGE},${TEST_REQUIRES_ROOT_PACKAGES}); do \
--		go test ${TESTFLAGS} \
-+		${GO} test ${TESTFLAGS} \
- 			-cover \
- 			-coverprofile=profile.out \
- 			-covermode=atomic $$pkg -test.root || exit; \
--- 
-2.27.0.212.ge8ba1cc988-goog
-
diff --git a/overlay-lakitu/app-emulation/containerd/files/consume_shim_logs_and_downgrade_shim_process.patch b/overlay-lakitu/app-emulation/containerd/files/consume_shim_logs_and_downgrade_shim_process.patch
deleted file mode 100644
index 5af2924..0000000
--- a/overlay-lakitu/app-emulation/containerd/files/consume_shim_logs_and_downgrade_shim_process.patch
+++ /dev/null
@@ -1,83 +0,0 @@
-From dab7bd0c4549a6a012004326f7415770c23afde4 Mon Sep 17 00:00:00 2001
-From: Brian Goff <cpuguy83@gmail.com>
-Date: Wed, 9 Sep 2020 16:42:35 -0700
-Subject: [PATCH] Always consume shim logs
-
-diff --git a/runtime/v1/shim/client/client.go b/runtime/v1/shim/client/client.go
-index 562ee6c..bb411c1 100644
---- a/runtime/v1/shim/client/client.go
-+++ b/runtime/v1/shim/client/client.go
-@@ -2,13 +2,10 @@
- 
- /*
-    Copyright The containerd Authors.
--
-    Licensed under the Apache License, Version 2.0 (the "License");
-    you may not use this file except in compliance with the License.
-    You may obtain a copy of the License at
--
-        http://www.apache.org/licenses/LICENSE-2.0
--
-    Unless required by applicable law or agreed to in writing, software
-    distributed under the License is distributed on an "AS IS" BASIS,
-    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-@@ -22,6 +19,7 @@ import (
- 	"context"
- 	"fmt"
- 	"io"
-+	"io/ioutil"
- 	"net"
- 	"os"
- 	"os/exec"
-@@ -67,22 +65,24 @@ func WithStart(binary, address, daemonAddress, cgroup string, debug bool, exitHa
- 		}
- 		defer f.Close()
- 
--		var stdoutLog io.ReadWriteCloser
--		var stderrLog io.ReadWriteCloser
--		if debug {
--			stdoutLog, err = v1.OpenShimStdoutLog(ctx, config.WorkDir)
--			if err != nil {
--				return nil, nil, errors.Wrapf(err, "failed to create stdout log")
--			}
--
--			stderrLog, err = v1.OpenShimStderrLog(ctx, config.WorkDir)
--			if err != nil {
--				return nil, nil, errors.Wrapf(err, "failed to create stderr log")
--			}
-+		stdoutCopy := ioutil.Discard
-+		stderrCopy := ioutil.Discard
-+		stdoutLog, err := v1.OpenShimStdoutLog(ctx, config.WorkDir)
-+		if err != nil {
-+			return nil, nil, errors.Wrapf(err, "failed to create stdout log")
-+		}
- 
--			go io.Copy(os.Stdout, stdoutLog)
--			go io.Copy(os.Stderr, stderrLog)
-+		stderrLog, err := v1.OpenShimStderrLog(ctx, config.WorkDir)
-+		if err != nil {
-+			return nil, nil, errors.Wrapf(err, "failed to create stderr log")
- 		}
-+		if debug {
-+			stdoutCopy = os.Stdout
-+			stderrCopy = os.Stderr
-+		}
-+
-+		go io.Copy(stdoutCopy, stdoutLog)
-+		go io.Copy(stderrCopy, stderrLog)
- 
- 		cmd, err := newCommand(binary, daemonAddress, debug, config, f, stdoutLog, stderrLog)
- 		if err != nil {
-diff --git a/runtime/v1/shim/service.go b/runtime/v1/shim/service.go
-index 6bd6aef..2f5a8c2 100644
---- a/runtime/v1/shim/service.go
-+++ b/runtime/v1/shim/service.go
-@@ -514,7 +514,7 @@ func (s *Service) checkProcesses(e runc.Exit) {
- 	}
- 	s.mu.Unlock()
- 	if p == nil {
--		log.G(s.context).Infof("process with id:%d wasn't found", e.Pid)
-+		log.G(s.context).Debugf("process with id:%d wasn't found", e.Pid)
- 		return
- 	}
- 	if ip, ok := p.(*process.Init); ok {