Skip to content

config.toml has empty "gitlab-runner-parent-id" #496

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

Closed
AlexEndris opened this issue May 25, 2022 · 2 comments · Fixed by #497
Closed

config.toml has empty "gitlab-runner-parent-id" #496

AlexEndris opened this issue May 25, 2022 · 2 comments · Fixed by #497

Comments

@AlexEndris
Copy link

Hi,

I've found that, for what ever reason, the user-data configuration doesn't seem to get the instance ID of the gitlab runner agent.

This variable
https://github.com/npalm/terraform-aws-gitlab-runner/blob/9d39138b7f526ebe7132c5d0bb1e4a50cea50626/template/gitlab-runner.tpl#L3

contains gitlab-runner-parent-id,.

This is also what the log says:

++ echo gitlab-runner-parent-id,
+ sed -i.bak s/__PARENT_TAG__/gitlab-runner-parent-id,/g /etc/gitlab-runner/config.toml

The curl call in the log to the instance-id endpoint show this:

++ curl http://169.254.169.254/latest/meta-data/instance-id
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0

+ PARENT_INSTANCE_ID=
+ PARENT_TAG=gitlab-runner-parent-id,

All other calls to metadata or getting the accesstokens work. It's just this one.

Funnily enough, a few lines above in the log, there is a call to http://169.254.169.254/latest/dynamic/instance-identity/document which return the instance-id. So maybe the metadata isn't available at this point in the EC2 creation process?

I can reproduce this issue with every deployment.

@npalm
Copy link
Collaborator

npalm commented May 25, 2022

We switched to IMDv2 with a require token. Did you checked if the token passed? See https://github.com/npalm/terraform-aws-gitlab-runner/blob/9d39138b7f526ebe7132c5d0bb1e4a50cea50626/template/logging.tpl#L40

@AlexEndris
Copy link
Author

AlexEndris commented May 25, 2022

Yes, indeed, the logs show that all the other calls for the instance ID work, but the one in gitlab-runner.tpl doesn't. Mabye you just didn't adjust that file during the switch as it is still showing this in the master branch:

https://github.com/npalm/terraform-aws-gitlab-runner/blob/9d39138b7f526ebe7132c5d0bb1e4a50cea50626/template/gitlab-runner.tpl#L2

Maybe it's enough to remove this line (Line 2 of the file) and adjust Line 3 to use the instanceId variable that's alreayd there?

Edit:
So essentially change

# Provide the parent instance id in the spawned runner tags
PARENT_INSTANCE_ID=$(curl http://169.254.169.254/latest/meta-data/instance-id);
PARENT_TAG="gitlab-runner-parent-id,$${PARENT_INSTANCE_ID}"

to

# Provide the parent instance id in the spawned runner tags
PARENT_TAG="gitlab-runner-parent-id,$${instanceId}"

or

# Provide the parent instance id in the spawned runner tags
PARENT_INSTANCE_ID=$(curl -s -H "X-aws-ec2-metadata-token: $token" http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r .instanceId)
PARENT_TAG="gitlab-runner-parent-id,$${PARENT_INSTANCE_ID}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants