-
Notifications
You must be signed in to change notification settings - Fork 17
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
Extract temporary service account token by name directly #373
Conversation
Signed-off-by: Jose R. Gonzalez <[email protected]>
secrets.append({"name": token_name}) | ||
secret_found = True | ||
break | ||
time.sleep(10) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you still need/wait to sleep some? Or is this no longer important/needed because the secrete is being proactively created?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sleep was moved to the top of the function, and is only executed on retries.
In #366, I modified the code that creates namespaces, RBAC resources, etc. used in certification workflows because OpenShift 4.16 (which is our current runtime platform) did not automatically populate tokens for the service accounts. In effect, I just manually created a secret so that the cluster would populate it with a token we could use.
Since then, I've noticed we had intermittent failures in nightly runs.
https://github.com/openshift-helm-charts/sandbox/actions/runs/10060735219/job/27809079797#step:17:18
When we search for the service account token, we parse the service account in the temporary namespace to see if it has secrets populated. In certain (or all modern) cases, the token secret may not be listed in the service account's list of secrets, so the code would then use
oc describe
to list a token secret, then parse that using regular expressions to find secret name, then extract the value, and so on.The failure we were seeing was because we would sometimes get a service account manifest back (in JSON format) with no
secrets
key. I don't know why, but that's neither here nor there. I had originally just wrapped this bit of code in a try/except KeyError block, but after reading it, I think decided to simplify it a bit.This PR refactors this code to extract the token from the token secret directly because we now know it's name (because we create it in this same code).
In the previous iteration of this code (described above), the token secret would have been generated by Kubernetes with a randomized name. Given we didn't know that name we would use regular expressions to match any possible names, and then read data from it.
Now that we know the token secret we care about will have a fixed name, we can query it directly and extract the temporary token from that.
Aside: this script and library needs some refactor, but I didn't do that here/yet. I'm just addressing the intermittence to reduce invalid E2E failures we've been seeing in nightly runs. Refactoring this is a future task.