open-consul/build-support/scripts/envoy-library-references.sh
Matt Keeler e909289454
Various bits of cleanup detected when using Go Workspaces (#17462)
TLDR with many modules the versions included in each diverged quite a bit. Attempting to use Go Workspaces produces a bunch of errors.

This commit:

1. Fixes envoy-library-references.sh to work again
2. Ensures we are pulling in go-control-plane@v0.11.0 everywhere (previously it was at that version in some modules and others were much older)
3. Remove one usage of golang/protobuf that caused us to have a direct dependency on it.
4. Remove deprecated usage of the Endpoint field in the grpc resolver.Target struct. The current version of grpc (v1.55.0) has removed that field and recommended replacement with URL.Opaque and calls to the Endpoint() func when needing to consume the previous field.
4. `go work init <all the paths to go.mod files>` && `go work sync`. This syncrhonized versions of dependencies from the main workspace/root module to all submodules
5. Updated .gitignore to ignore the go.work and go.work.sum files. This seems to be standard practice at the moment.
6. Update doc comments in protoc-gen-consul-rate-limit to be go fmt compatible
7. Upgraded makefile infra to perform linting, testing and go mod tidy on all modules in a flexible manner.
8. Updated linter rules to prevent usage of golang/protobuf
9. Updated a leader peering test to account for an extra colon in a grpc error message.
2023-06-05 16:08:39 -04:00

92 lines
2.4 KiB
Bash

#!/bin/bash
####
# envoy-library-references.sh
#
# This script ensures that all of the protobuf packages present in the
# github.com/envoyproxy/go-control-plane library are referenced in the consul
# codebase somewhere so that the ultimate binary doesn't eliminate those
# packages. When the packages are linked in they use proto.RegisterFile() to
# globally register the types in the protobuf machinery so that they are
# available for decoding.
#
# We primarily need this for the Escape Hatch feature where users can provide
# arbitrary xDS JSON for Consul to decode. If extension points use *any.Any and
# use an extention package that Consul itself doesn't use then it won't decode
# unless the package is linked into the binary.
#
####
set -euo pipefail
unset CDPATH
cd "$(dirname "$0")" # build-support/scripts
cd ../.. # <ROOT>
if [[ ! -f GNUmakefile ]] || [[ ! -f go.mod ]]; then
echo "not in root consul checkout: ${PWD}" >&2
exit 1
fi
readonly LIBRARY_VERSION="$(grep -e "github.com/envoyproxy/go-control-plane[[:space:]]" go.mod | awk '{print $2}')"
readonly OUTFILE=z_xds_packages.go
echo "Fetching envoyproxy/go-control-plane @ ${LIBRARY_VERSION}..."
rm -rf _envoy_tmp
mkdir _envoy_tmp
trap "rm -rf _envoy_tmp" EXIT
(
cd _envoy_tmp
git clone https://github.com/envoyproxy/go-control-plane
cd go-control-plane
git checkout -b consul-temp "${LIBRARY_VERSION}"
IFS=$'\n' candidates=($(find . -name *.pb.go -a -type f | sed 's@/[^/]*\.pb\.go$@@' | sort -u))
echo "Generating a fresh agent xds ${OUTFILE} file..."
cat <<-EOF > "${OUTFILE}"
// Code generated by envoy-library-references.sh. DO NOT EDIT.
package xds
import (
EOF
for cand in "${candidates[@]}"; do
import_name="${cand#./}"
echo " _ \"github.com/envoyproxy/go-control-plane/${import_name}\"" >> "${OUTFILE}"
done
echo ")" >> "${OUTFILE}"
goimports -w "${OUTFILE}"
mv -f "${OUTFILE}" ../../agent/xds
echo "Generating a fresh troubleshoot ${OUTFILE} file..."
cat <<-EOF > "${OUTFILE}"
// Code generated by envoy-library-references.sh. DO NOT EDIT.
package troubleshoot
import (
EOF
for cand in "${candidates[@]}"; do
import_name="${cand#./}"
echo " _ \"github.com/envoyproxy/go-control-plane/${import_name}\"" >> "${OUTFILE}"
done
echo ")" >> "${OUTFILE}"
goimports -w "${OUTFILE}"
mv -f "${OUTFILE}" ../../troubleshoot/proxy
)
echo "tidying dependencies..."
make go-mod-tidy