How do I retrieve a GitLab hosted Kubernetes Agent ClusterAgentID to delete the Agent?

Viewed 407

The docs here: https://docs.gitlab.com/ee/user/clusters/agent/#remove-the-gitlab-kubernetes-agent

say to use the GraphQL endpoint do delete the agent and token. However, the GraphQL mutations require a ClusterAgentID: https://docs.gitlab.com/ee/api/graphql/reference/#mutationclusteragentdelete

mutation deleteAgent {
  clusterAgentDelete(input: { id: "<cluster-agent-id>" } ) {
    errors
  }
}

mutation deleteToken {
  clusterAgentTokenDelete(input: { id: "<cluster-agent-token-id>" }) {
    errors
  }
}

There is no corresponding mechanism to query for the ID nor is there a way to find it in the UI (and it does not appear to be part of the URL based on the documented format). The docs do not show where to retrieve the IDs from either.

Looking for a way to delete the Kubernetes agent in my GitLab project without having to delete the whole project.

2 Answers

Actually, you now have an alternative solution, with GitLab 14.7 (January 2022):

Delete a GitLab Agent for Kubernetes from the UI

The GitLab Agent for Kubernetes is tested and adopted by hundreds of GitLab customers each month.

A few users noticed that it’s not straightforward to remove a registered agent from GitLab.

Until now, the agent could be removed only through the GraphQL API.

Introduced in GitLab 14.7, you can delete an agent directly from the GitLab UI as well.

When you delete the agent, GitLab revokes its tokens and the given connection stops working immediately.

See Documentation and Issue.

Related