Skip to content
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

Clean up agents from pool when Terraform destroy is called #3

Open
jcorioland opened this issue Jun 3, 2020 · 11 comments
Open

Clean up agents from pool when Terraform destroy is called #3

jcorioland opened this issue Jun 3, 2020 · 11 comments
Assignees
Labels
enhancement New feature or request

Comments

@jcorioland
Copy link
Collaborator

jcorioland commented Jun 3, 2020

Currently, if you call the terraform destroy commands, all the containers instances are removed, but the agents are still present in the Azure DevOps agents pool. They are marked as offline, so no job can be scheduled on it, but still there and have to be removed manually.

image

We should find a way to clean up automatically when terraform destroy is called. Maybe using a local executer or something like that.

@jcorioland jcorioland added the enhancement New feature or request label Jun 3, 2020
@jcorioland jcorioland self-assigned this Jun 3, 2020
@mozts2005
Copy link
Contributor

@jcorioland I have fixed this in use case and would be happy to add a PR for the fix.

@jcorioland
Copy link
Collaborator Author

@mozts2005 awesome, I am happy to get contributions on the project! How did you fix this in your use case? Looking forward for the PR. Thanks!

@mozts2005
Copy link
Contributor

I did this by adding the Azure DevOps provider and creating the Pool in the state file.

@mozts2005
Copy link
Contributor

I have been able to remove individual agents in AKS clusters when the containers get a safe shutdown by updating the startup.sh script to call the cleanup function. but I have not been able to get an ACI to perform a safe shutdown.

@jcorioland
Copy link
Collaborator Author

@mozts2005
I did this by adding the Azure DevOps provider and creating the Pool in the state file.
On this one, I think you are talking about #4 and not this issue. I have a work in progress on this one, and indeed I am using the new Azure DevOps provider.

I have been able to remove individual agents in AKS clusters when the containers get a safe shutdown by updating the startup.sh script to call the cleanup function. but I have not been able to get an ACI to perform a safe shutdown.

This is exactly my problem, I cannot find a way to gracefully shutdown an ACI container.

@yuri-tieto
Copy link

yuri-tieto commented Sep 3, 2020

I have been able to remove individual agents in AKS clusters when the containers get a safe shutdown by updating the startup.sh script to call the cleanup function. but I have not been able to get an ACI to perform a safe shutdown.

@mozts2005 can you share the code for calling cleanup of the agent? I see reference to config.sh, but can't find it inside this repository.

@mozts2005
Copy link
Contributor

mozts2005 commented Sep 3, 2020

add this to the bottom of the start.sh

print_header "2. Running Azure Pipelines agent..."

# `exec` the node runtime so it's aware of TERM and INT signals
# AgentService.js understands how to handle agent self-update and restart
exec ./externals/node/bin/node ./bin/AgentService.js interactive --once & wait $!

# We expect the above process to exit when it runs once,
# so we now run a cleanup process to remove this agent
# from the pool
cleanup

the cleanup function can be viewed here https://github.com/Azure/terraform-azurerm-aci-devops-agent/blob/master/docker/linux/start.sh#L31

the config.sh is part of the agent that is installed by the startup.sh

@mozts2005
Copy link
Contributor

Are there any changes need to PR #11?

@joshjohanning
Copy link

@jcorioland did the above PR solve the cleanup issue on destroy (not sure if you tested it yourself); is this something you were still pursuing?

@jcorioland
Copy link
Collaborator Author

@soccerjoshj07 for some reason it has not been finished. I am looking at it right now to finish end to end tests and merge. Thanks!

@bitsofinfo
Copy link

any update on this?

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

Successfully merging a pull request may close this issue.

5 participants