Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
91e5181
tear-down PR dev cluster and children
davdhacs Mar 24, 2025
199d647
lint
davdhacs Mar 24, 2025
796e181
comment after deployed
davdhacs Mar 24, 2025
a9f9d22
ignore shellcheck quote
davdhacs Mar 24, 2025
de657bd
directly on runner
davdhacs Mar 24, 2025
ea89896
pr create directly on runner also
davdhacs Mar 24, 2025
1d8455e
lint on PR also
davdhacs Mar 24, 2025
12255f4
try line after shebang
davdhacs Mar 24, 2025
d548c7c
gh use if hub-comment fails
davdhacs Mar 24, 2025
2ee6702
remove container
davdhacs Mar 24, 2025
ba84619
only specific place
davdhacs Mar 24, 2025
675bb10
use HOME
davdhacs Mar 24, 2025
36a1efd
retry pull from dev server
davdhacs Mar 24, 2025
475545d
unnecessary use of templating
davdhacs Mar 24, 2025
f35293e
use tmpdir
davdhacs Mar 24, 2025
d8e5869
log github event object
davdhacs Mar 24, 2025
bb639d3
dump event obj as json
davdhacs Mar 24, 2025
89955d8
just use the html_url
davdhacs Mar 24, 2025
a14ef58
restore no leading space
davdhacs Mar 24, 2025
d475831
remove bats tests
davdhacs Mar 24, 2025
c2b543a
set gopath
davdhacs Mar 25, 2025
a032797
lint
davdhacs Mar 25, 2025
327c1af
closed as sync workflow
davdhacs Mar 25, 2025
cbfeb50
needs gcloud
davdhacs Mar 25, 2025
909ecc0
try some creates
davdhacs Mar 25, 2025
53de1c1
wait for cluster
davdhacs Mar 25, 2025
fdf5b2a
wait for infra installed also
davdhacs Mar 25, 2025
52f1a9b
dev token for pr dev cluster
davdhacs Mar 25, 2025
ec144c7
log cluster check
davdhacs Mar 25, 2025
3718739
separate concurrency
davdhacs Mar 25, 2025
aab4074
get artifacts before trying
davdhacs Mar 25, 2025
9f12318
check deployment
davdhacs Mar 25, 2025
ccc1e6e
try delete again
davdhacs Mar 25, 2025
947b1f5
check exists before deleting
davdhacs Mar 25, 2025
5fe3724
delete dev cluster
davdhacs Mar 25, 2025
25a425b
try delete after tests
davdhacs Mar 26, 2025
c71913d
Merge branch 'master' into cleanup-pr-cluster
davdhacs Mar 26, 2025
8af088b
always run
davdhacs Mar 27, 2025
322fcf8
list all not quiet
davdhacs Mar 27, 2025
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
116 changes: 116 additions & 0 deletions .github/workflows/PR-close.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: PR Workflow

on:
pull_request:
types:
- closed

defaults:
run:
working-directory: go/src/github.com/stackrox/infra

concurrency: pr-${{ github.ref }}

env:
CLUSTER_NAME: infra-pr-${{ github.event.pull_request.number }}
GH_TOKEN: ${{ secrets.RHACS_BOT_GITHUB_TOKEN }}

jobs:
destroy:
runs-on: ubuntu-latest
env:
KUBECONFIG: /tmp/kubeconfig
INFRA_TOKEN: ${{ secrets.INFRA_TOKEN }}
INFRACTL: bin/infractl -k -e localhost:8443
USE_GKE_GCLOUD_AUTH_PLUGIN: "True"

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
path: go/src/github.com/stackrox/infra

- name: Authenticate to GCloud
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.INFRA_CI_AUTOMATION_GCP_SA }}

- name: Set up Cloud SDK
uses: "google-github-actions/setup-gcloud@v2"
with:
install_components: "gke-gcloud-auth-plugin"

- name: Download production infractl
uses: stackrox/actions/infra/install-infractl@v1

- name: Wait for cluster
run: |
set -xo pipefail
for I in {1..60}; do
~/.local/bin/infractl get "$CLUSTER_NAME" | tee >( cat >&2 ) | grep READY && break || echo $?
sleep 60
done
~/.local/bin/infractl artifacts "$CLUSTER_NAME" -d /tmp/
kubectl get nodes -o wide || true
for I in {1..5}; do
kubectl -n infra rollout status deploy/infra-server-deployment --timeout=300s && break || echo $?
sleep 60
done

- name: Download branch infractl
run: |
kubectl -n infra port-forward svc/infra-server-service 8443:8443 > /dev/null 2>&1 &
sleep 10

kubectl -n infra logs -l app=infra-server --tail=-1

make pull-infractl-from-dev-server
$INFRACTL version

kill %1

- name: Destroy created clusters still running
env:
INFRA_TOKEN: ${{ secrets.INFRA_TOKEN_DEV }}
run: |
set -x
kubectl -n infra port-forward svc/infra-server-service 8443:8443 > /dev/null 2>&1 &
sleep 10

echo 'For 30 minutes, list and delete child clusters that are not failed.'
for I in {1..30}; do
$INFRACTL list --all --quiet
count=0
# Continue if running or destroying
for cluster in $($INFRACTL list --all --quiet --status='READY,CREATING,DESTROYING'); do
echo "$(( ++count )): ${cluster}"
done
if [[ $count -gt 0 ]]; then
echo 'Active clusters found. Deleting ...' | tee -a "$GITHUB_STEP_SUMMARY"
else
echo 'No active clusters found.'
break
fi
# shellcheck disable=SC2086
for cluster in $($INFRACTL list --all --quiet --status='READY,CREATING'); do
$INFRACTL get "${cluster}" \
&& $INFRACTL delete "${cluster}"
done \
| tee -a "$GITHUB_STEP_SUMMARY"
echo "(sleep 1 minute then check again. try $I/30)"
sleep 60
done

kill %1

- name: Destroy PR dev cluster
run: |
~/.local/bin/infractl delete "$CLUSTER_NAME"
echo "Deleted PR dev cluster ${CLUSTER_NAME}" | tee -a "$GITHUB_STEP_SUMMARY"

- name: Comment on PR
run: |
gh pr comment "${{ github.event.number }}" \
--body "Development cluster deleted."
93 changes: 86 additions & 7 deletions .github/workflows/PR.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ jobs:
- build-and-push
- create-dev-cluster
runs-on: ubuntu-latest
container:
image: quay.io/stackrox-io/apollo-ci:stackrox-test-0.4.4

steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -66,10 +63,8 @@ jobs:
- build-and-push
- create-dev-cluster
runs-on: ubuntu-latest
container:
image: quay.io/stackrox-io/apollo-ci:stackrox-test-0.4.4
env:
KUBECONFIG: /github/home/artifacts/kubeconfig
KUBECONFIG: /tmp/kubeconfig
INFRA_TOKEN: ${{ secrets.INFRA_TOKEN }}
INFRACTL: bin/infractl -k -e localhost:8443
USE_GKE_GCLOUD_AUTH_PLUGIN: "True"
Expand Down Expand Up @@ -101,7 +96,7 @@ jobs:

- name: Download artifacts
run: |
/github/home/.local/bin/infractl artifacts "$CLUSTER_NAME" -d /github/home/artifacts >> "$GITHUB_STEP_SUMMARY"
~/.local/bin/infractl artifacts "$CLUSTER_NAME" -d /tmp/ >> "$GITHUB_STEP_SUMMARY"
kubectl get nodes -o wide || true

- name: Deploy infra to dev cluster
Expand Down Expand Up @@ -143,6 +138,11 @@ jobs:

kill %1

- name: Comment on PR
run: |
gh pr comment "${{ github.event.number }}" \
--body "Deployment to development cluster completed."

- name: Install Argo CLI
run: |
ARGO_VERSION=$(grep "github.com/argoproj/argo-workflows/v3" go.mod | awk '{ print $2 }')
Expand All @@ -157,10 +157,89 @@ jobs:
run: |
make argo-workflow-lint

- name: create example clusters to delete
env:
INFRA_TOKEN: ${{ secrets.INFRA_TOKEN_DEV }}
run: |
set +e
set -x
kubectl -n infra port-forward svc/infra-server-service 8443:8443 > /dev/null 2>&1 &
sleep 10

$INFRACTL create gke-default tstlonglifer --lifespan 8h
$INFRACTL create gke-default tstshortlifer --lifespan 30s
$INFRACTL create gke-default tstdestroyed --lifespan 2h

$INFRACTL delete tstdestroyed --json

$INFRACTL list --all --quiet

kill %1

- name: Run Go e2e tests
env:
INFRA_TOKEN: ${{ secrets.INFRA_TOKEN_DEV }}
run: |
kubectl -n infra port-forward svc/infra-server-service 8443:8443 > /dev/null 2>&1 &
sleep 5
GOPATH=$(go env GOPATH)
export GOPATH
make go-e2e-tests

- name: Wait for cluster
if: always()
run: |
set -xo pipefail
for I in {1..60}; do
~/.local/bin/infractl get "$CLUSTER_NAME" | tee >( cat >&2 ) | grep READY && break || echo $?
sleep 60
done
~/.local/bin/infractl artifacts "$CLUSTER_NAME" -d /tmp/
kubectl get nodes -o wide || true
for I in {1..5}; do
kubectl -n infra rollout status deploy/infra-server-deployment --timeout=300s && break || echo $?
sleep 60
done

- name: Destroy created clusters still running
if: always()
env:
INFRA_TOKEN: ${{ secrets.INFRA_TOKEN_DEV }}
run: |
set -x
kubectl -n infra port-forward svc/infra-server-service 8443:8443 > /dev/null 2>&1 &
sleep 10

echo 'For 30 minutes, list and delete child clusters that are not failed.'
for I in {1..30}; do
$INFRACTL list --all
count=0
# Continue if running or destroying
for cluster in $($INFRACTL list --all --quiet --status='READY,CREATING,DESTROYING'); do
echo "$(( ++count )): ${cluster}"
done
if [[ $count -gt 0 ]]; then
echo 'Active clusters found. Deleting ...' | tee -a "$GITHUB_STEP_SUMMARY"
else
echo 'No active clusters found.'
break
fi
# shellcheck disable=SC2086
for cluster in $($INFRACTL list --all --quiet --status='READY,CREATING'); do
$INFRACTL get "${cluster}" \
&& $INFRACTL delete "${cluster}"
done \
| tee -a "$GITHUB_STEP_SUMMARY"
echo "(sleep 1 minute then check again. try $I/30)"
sleep 60
done

kill %1

- name: Destroy PR dev cluster
if: always()
run: |
~/.local/bin/infractl delete "$CLUSTER_NAME"
echo "Deleted PR dev cluster ${CLUSTER_NAME}" | tee -a "$GITHUB_STEP_SUMMARY"
gh pr comment "${{ github.event.number }}" \
--body "Development cluster deleted."
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ pull-infractl-from-dev-server:
@mkdir -p bin
@rm -f bin/infractl
set -o pipefail; \
curl --retry 3 --insecure --silent --show-error --fail --location https://localhost:8443/v1/cli/$(shell go env GOOS)/$(shell go env GOARCH)/upgrade \
curl --retry 3 --retry-all-errors --retry-delay 5 --insecure --silent --show-error --fail --location https://localhost:8443/v1/cli/$(shell go env GOOS)/$(shell go env GOARCH)/upgrade \
| jq -r ".result.fileChunk" \
| base64 -d \
> bin/infractl
Expand Down
18 changes: 9 additions & 9 deletions scripts/add-PR-comment-for-deploy-to-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ add_PR_comment_for_deploy_to_dev() {

local tmpfile
tmpfile=$(mktemp)
cat > "$tmpfile" <<- EOT
A single node development cluster ({{.Env.DEV_CLUSTER_NAME}}) was allocated in production infra for this PR.
cat > "$tmpfile" <<EOT
A single node development cluster (${DEV_CLUSTER_NAME}) was allocated in production infra for this PR.

CI will attempt to deploy \`{{.Env.IMAGE_NAME}}\` to it.
CI will attempt to deploy \`${IMAGE_NAME}\` to it.

:electric_plug: You can **connect** to this cluster with:
\`\`\`
gcloud container clusters get-credentials {{.Env.DEV_CLUSTER_NAME}} --zone us-central1-a --project acs-team-temp-dev
gcloud container clusters get-credentials ${DEV_CLUSTER_NAME} --zone us-central1-a --project acs-team-temp-dev
\`\`\`

:hammer_and_wrench: And pull **infractl** from the deployed dev infra-server with:
Expand Down Expand Up @@ -57,18 +57,18 @@ make helm-deploy
### Logs

Logs for the development infra depending on your @redhat.com authuser:
- [authuser=0](https://console.cloud.google.com/logs/query;query=resource.labels.cluster_name%3D%22{{.Env.DEV_CLUSTER_NAME}}%22%0Aresource.labels.container_name%3D%22infra-server%22?project=acs-team-temp-dev&authuser=0)
- [authuser=1](https://console.cloud.google.com/logs/query;query=resource.labels.cluster_name%3D%22{{.Env.DEV_CLUSTER_NAME}}%22%0Aresource.labels.container_name%3D%22infra-server%22?project=acs-team-temp-dev&authuser=1)
- [authuser=2](https://console.cloud.google.com/logs/query;query=resource.labels.cluster_name%3D%22{{.Env.DEV_CLUSTER_NAME}}%22%0Aresource.labels.container_name%3D%22infra-server%22?project=acs-team-temp-dev&authuser=2)
- [authuser=0](https://console.cloud.google.com/logs/query;query=resource.labels.cluster_name%3D%22${DEV_CLUSTER_NAME}%22%0Aresource.labels.container_name%3D%22infra-server%22?project=acs-team-temp-dev&authuser=0)
- [authuser=1](https://console.cloud.google.com/logs/query;query=resource.labels.cluster_name%3D%22${DEV_CLUSTER_NAME}%22%0Aresource.labels.container_name%3D%22infra-server%22?project=acs-team-temp-dev&authuser=1)
- [authuser=2](https://console.cloud.google.com/logs/query;query=resource.labels.cluster_name%3D%22${DEV_CLUSTER_NAME}%22%0Aresource.labels.container_name%3D%22infra-server%22?project=acs-team-temp-dev&authuser=2)

Or:
\`\`\`
kubectl -n infra logs -l app=infra-server --tail=1 -f
\`\`\`

EOT

hub-comment -type deploy -template-file "$tmpfile"
hub-comment -type deploy -template-file "$tmpfile" \
|| gh pr comment "${url}" --edit-last --create-if-none --body-file "$tmpfile"
}

add_PR_comment_for_deploy_to_dev "$@"
Loading