Skip to content

Commit

Permalink
networkglue fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
toddnni committed Sep 16, 2024
1 parent 1f9119e commit 45ab62b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ First, generate a GitHub personal access token (PAT) with minimal permissions fo

- https://github.com/settings/personal-access-tokens/
- limit to the specific repository
- contents (read)
- contents (write, needs for branches)
- PRs (write)

Install (token will be needed here)
Expand Down
2 changes: 1 addition & 1 deletion network-glue/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ghcr.io/flant/shell-operator:latest
RUN apk add git
RUN apk add git curl
ADD hooks /hooks

2 changes: 1 addition & 1 deletion network-glue/hooks/bin/clone-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fi
# Clone the repository using the GitHub token
echo "Cloning the repository..."
rm -rf "$REPO_DIR"
git clone https://"${GIT_TOKEN}":x-oauth-basic@"$REPO_URL" "$REPO_DIR"
git clone https://"${GIT_TOKEN}":x-oauth-basic@"${REPO_URL#https://}" "$REPO_DIR"
cd "$REPO_DIR"

# Create a new branch for the changes
Expand Down
13 changes: 9 additions & 4 deletions network-glue/hooks/bin/create-pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ set -u
# BRANCH_NAME
# FILE_TO_UPDATE
# Configuration
GIT_USER="shell-operator"
GIT_EMAIL="shell-operator@example.com"
COMMIT_MESSAGE="Update configuration file"
PR_TITLE="Proposal: Update Configuration $FILE_TO_UPDATE"
PR_BODY="This PR proposes updates to the configuration file."
Expand All @@ -23,13 +25,16 @@ if [ -z "$GIT_TOKEN" ]; then
fi

# Add and commit the changes
cd "$REPO_DIR"
git add "$FILE_TO_UPDATE"
echo "Committing the changes..."
echo "Committing the changes with $GIT_USER <$GIT_EMAIL>..."
git config --global user.name "$GIT_USER"
git config --global user.email "$GIT_EMAIL"
git commit -m "$COMMIT_MESSAGE"

# Push the changes to the new branch
echo "Pushing the changes to the branch $BRANCH_NAME..."
git push origin "$BRANCH_NAME"
git push origin "$BRANCH_NAME" -f

# example https://github.com/toddnni/pe-automation-demo-2024-repo
REPO_NAME="${REPO_URL##*/}"
Expand All @@ -40,9 +45,9 @@ echo "Resolved repo owner and name: $REPO_OWNER, $REPO_NAME"

echo "Creating a pull request..."
curl -X POST \
-H "Authorization: token ${GITHUB_TOKEN}" \
-H "Authorization: token ${GIT_TOKEN}" \
-H "Accept: application/vnd.github.v3+json" \
--fail
--fail \
-d @- \
"https://github.com/repos/${REPO_OWNER}/${REPO_NAME}/pulls" <<EOF
{
Expand Down
5 changes: 3 additions & 2 deletions network-glue/hooks/hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ else
type=$(jq -r '.[0].type' "${BINDING_CONTEXT_PATH}")
namespace=$(jq -r '.[0].object.metadata.namespace' "${BINDING_CONTEXT_PATH}")
name=$(jq -r '.[0].object.metadata.name' "${BINDING_CONTEXT_PATH}")
version=$(jq -r '.[0].object.metadata.resourceVersion' "${BINDING_CONTEXT_PATH}")
eventType=$(jq -r '.[0].watchEvent' "${BINDING_CONTEXT_PATH}")
source=$(jq -r '.[0].object.spec.source.networkCIDR' "${BINDING_CONTEXT_PATH}")
target=$(jq -r '.[0].object.spec.target.networkCIDR' "${BINDING_CONTEXT_PATH}")
targetPort=$(jq -r '.[0].object.spec.target.port' "${BINDING_CONTEXT_PATH}")

export REPO_URL="$REPO_URL"
export REPO_URL="$(echo $REPO_URL | tr -d '\n ')" # strip newlines
export REPO_DIR=/git
export BRANCH_NAME="feature/update-config-$(date +%Y%m%d-%H%M%S)"
export BRANCH_NAME="feature/update-config-$namepspace-$name-$version"
export FILE_TO_UPDATE="$REPO_DIR/$namespace-$name.json"

if [[ $type == "Synchronization" ]] ; then
Expand Down

0 comments on commit 45ab62b

Please sign in to comment.