Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ztp: CNF-14991: Fix instability in policy-generator-plugin usage #2077

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ztp/tools/pgt2acmpg/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kustomize/
40 changes: 31 additions & 9 deletions ztp/tools/pgt2acmpg/scripts/build-acmpg-plugin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,38 @@ set -o errexit -o nounset -o pipefail
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CNF_FEATURE_DEPLOY_ROOT=$SCRIPT_DIR/../../../..

# Builds the latest version of policy-generator-plugin
# We can no longer use go install because of https://github.com/golang/go/issues/44840
# Instead we need to clone the policy-generator-plugin project and build the executable
# Due to https://github.com/golang/go/issues/44840 we are unable to use go install
# Instead we will download the source code and compile it ourselves
TMP_DIR=$(mktemp -d -p .)
echo "Created $TMP_DIR"
cd "$TMP_DIR"
git clone --depth 1 --branch main --single-branch https://github.com/open-cluster-management-io/policy-generator-plugin.git
cd policy-generator-plugin
echo "Created ${TMP_DIR}"
pushd "${TMP_DIR}"

# The details we will use to query ACM
ACM_FORK="stolostron"
fontivan marked this conversation as resolved.
Show resolved Hide resolved
ACM_BRANCH="main"
fontivan marked this conversation as resolved.
Show resolved Hide resolved

# We need to check what version of the policy generator tag is in use
POLICY_GENERATOR_TAG=$(
curl "https://raw.githubusercontent.com/${ACM_FORK}/multicloud-operators-subscription/refs/heads/${ACM_BRANCH}/build/Dockerfile" \
| awk '/ENV POLICY_GENERATOR_TAG=/ {print $2}' | cut -d= -f2-
)

# Print the tag to make diagnosing issues easier
echo "Detected POLICY_GENERATOR_TAG=${POLICY_GENERATOR_TAG}"

# Download the matching branch
git clone --depth 1 --branch "${POLICY_GENERATOR_TAG}" --single-branch "https://github.com/${ACM_FORK}/policy-generator-plugin.git"

# build binary and copy it out
pushd "policy-generator-plugin"
go mod vendor
make build-binary
cp PolicyGenerator "$1"
rm -rf "$TMP_DIR"
echo "Deleted $TMP_DIR"

# popd twice to get back where we started
popd
popd

# cleanup directory
rm -rf "${TMP_DIR}"
echo "Deleted ${TMP_DIR}"