Your team wants preview environments per PR on EKS, destroyed when the PR closes. Design the workflow.
AdvancedScenarioPipeline Design & Triggers
Answer
Situation read → Lifecycle tied to PR events; must be safe for forks.
What I'd do →
- Trigger on
pull_requesttypes[opened, synchronize, reopened, labeled, closed], run only when labelpreviewexists and the PR is from the same repo:if: github.event.pull_request.head.repo.full_name == github.repository && contains(github.event.pull_request.labels.*.name, 'preview') - Deploy job (not closed): build image tagged
pr-${{ github.event.number }},helm upgrade --install pr-123 ./chart -n preview-pr-123 --create-namespace, environmentpreviewwithurl. - Teardown job:
if: github.event.action == 'closed',helm uninstallandkubectl delete ns. concurrency: preview-${{ github.event.number }}without cancel for teardown.- A nightly job deletes namespaces whose PR is closed, in case teardown failed.
Why → Fork PRs have no secrets, so restricting to same-repo PRs avoids failures and abuse.
Interview tip → Always mention the garbage collector job; teardown hooks fail eventually.
More on Pipeline Design & Triggers
You join a team whose single 900-line workflow runs everything on every push to every branch. How do you restructure it?IntermediatePushing to a PR branch runs CI twice (once for push, once for pull_request). How do you fix it?BeginnerProduct wants a "Deploy to staging" button that lets QA pick a version. Design it.BeginnerA nightly security scan should run at 02:00 India time on weekdays and also be runnable on demand. Write it.BeginnerTwo workflows must run in sequence: CI then a separate deploy workflow owned by another team. How do you link them?IntermediateA merge queue is enabled, but PRs sit in the queue forever. What is your design fix?Intermediate