After Runner re-register, it should be enabled for all the specific projects that it was enabled for before
Situation :
Using k8s integration at project level, using the same project as cluster management project.
Using only gitlab-runner from cluster management project after adding the k8s cluster intergration.
Using k8s v1.18 - works totally fine only if only using runner.
Then after enabling the runner for a few other projects it starts picking up jobs for other projects as well.
Problem:
Everytime I update values.yaml for gitlab-runner it gets re-deployed and re-registered as well, but re-registered only to the cluster management project.
So what I have to do now is,
fetch the runner ID (with heck of a sanity check) before registering it
RUNNER_ID=$(curl -s --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
"https://gitlab.com/api/v4/projects/${CI_PROJECT_ID}/runners?type=project_type" | \
jq --arg name "$(kubectl get pods -n gitlab-managed-apps --sort-by=.metadata.creationTimestamp | \
grep "^runner-gitlab-runner" | \
tail -1 | \
awk '{print $1}')" \
'.[] | select(.description | contains($name)) | .id')
then fetch projects' ID for which I enabled this runner
PROJECTS=$(curl -s \
--header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
"https://gitlab.com/api/v4/runners/${RUNNER_ID}" | \
jq '.projects[].id')
then run
gitlab-managed-apps /usr/local/share/gitlab-managed-apps/helmfile.yaml
then fetch the new register runner ID (${NEW_RUNNER_ID}) (with the same above command)
then register the runner for all ${PROJECTS}
while IFS= read -r id; do
echo "Enable runner ${NEW_RUNNER_ID} for Project ID : ${id}";
curl \
-s --request POST \
--header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
"https://gitlab.com/api/v4/projects/${id}/runners" \
--form "runner_id=${NEW_RUNNER_ID}" | \
jq '.' ; done<<<"${projects}"
Solution:
Well this is not a bug but a feature request.
It would be really
Because this is not an uncommon scenario, I think so.