Skip to content

Commit

Permalink
add poll runner profile cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticroentgen committed May 6, 2024
1 parent 4eee3d9 commit b704e1e
Showing 1 changed file with 41 additions and 13 deletions.
54 changes: 41 additions & 13 deletions PoolManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,23 +254,51 @@ private async Task CleanUpRunners(List<GithubTargetConfiguration> targetConfigs,
foreach (Pool pool in githubTarget.Pools)
{
// get all idle runners of size
List<GitHubRunner> idlePoolRunner = ghIdleRunners.Where(x => x.Labels.Any(y => y.Name == pool.Size)).ToList();
while (idlePoolRunner.Count > pool.NumRunners)
if (pool.Profile == "default")
{
GitHubRunner r = idlePoolRunner.PopAt(0);
// Remove excess runners
_logger.LogInformation($"Removing excess runner {r.Name} from {githubTarget.Name}");
bool _ = githubTarget.Target switch
List<GitHubRunner> idlePoolRunner = ghIdleRunners.Where(x => x.Labels.Any(y => y.Name == pool.Size)).ToList();
while (idlePoolRunner.Count > pool.NumRunners)
{
TargetType.Organization => await GitHubApi.RemoveRunnerFromOrg(githubTarget.Name, githubTarget.GitHubToken, r.Id),
TargetType.Repository => await GitHubApi.RemoveRunnerFromRepo(githubTarget.Name, githubTarget.GitHubToken, r.Id),
_ => throw new ArgumentOutOfRangeException()
};
long? htzSrvId = allHtzSrvs.FirstOrDefault(x => x.Name == r.Name)?.Id;
if (htzSrvId.HasValue)
GitHubRunner r = idlePoolRunner.PopAt(0);
// Remove excess runners
_logger.LogInformation($"Removing excess runner {r.Name} from {githubTarget.Name}");
bool _ = githubTarget.Target switch
{
TargetType.Organization => await GitHubApi.RemoveRunnerFromOrg(githubTarget.Name, githubTarget.GitHubToken, r.Id),
TargetType.Repository => await GitHubApi.RemoveRunnerFromRepo(githubTarget.Name, githubTarget.GitHubToken, r.Id),
_ => throw new ArgumentOutOfRangeException()
};
long? htzSrvId = allHtzSrvs.FirstOrDefault(x => x.Name == r.Name)?.Id;
if (htzSrvId.HasValue)
{
await _cc.DeleteRunner(htzSrvId.Value);
}
}
}
else
{
List<GitHubRunner> idlePoolRunner = ghIdleRunners.Where(x =>
x.Labels.Any(y => y.Name == pool.Size) &&
x.Labels.Any(y => y.Name == $"profile-{pool.Profile}")
).ToList();
while (idlePoolRunner.Count > pool.NumRunners)
{
await _cc.DeleteRunner(htzSrvId.Value);
GitHubRunner r = idlePoolRunner.PopAt(0);
// Remove excess runners
_logger.LogInformation($"Removing excess runner {r.Name} from {githubTarget.Name}");
bool _ = githubTarget.Target switch
{
TargetType.Organization => await GitHubApi.RemoveRunnerFromOrg(githubTarget.Name, githubTarget.GitHubToken, r.Id),
TargetType.Repository => await GitHubApi.RemoveRunnerFromRepo(githubTarget.Name, githubTarget.GitHubToken, r.Id),
_ => throw new ArgumentOutOfRangeException()
};
long? htzSrvId = allHtzSrvs.FirstOrDefault(x => x.Name == r.Name)?.Id;
if (htzSrvId.HasValue)
{
await _cc.DeleteRunner(htzSrvId.Value);
}
}

}
}

Expand Down

0 comments on commit b704e1e

Please sign in to comment.