如何检索 GitLab 托管的 Kubernetes 代理 ClusterAgentID 以删除代理?

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

此处的文档:https://docs.gitlab.com/ee/user/clusters/agent/#remove-the-gitlab-kubernetes-agent

说使用 GraphQL 端点删除代理和令牌。但是,GraphQL 突变需要 ClusterAgentIDhttps://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
  }
}

没有相应的机制来查询 ID,也没有办法在 UI 中找到它(并且根据记录,它似乎不是 URL 的一部分格式)。文档没有显示从哪里检索 ID。

寻找一种方法来删除我的 GitLab 项目中的 Kubernetes 代理,而不必删除整个项目。

找到答案:

{
  project(fullPath: "path/to/your/project") {
    clusterAgents {
      nodes {
        id
        name
      }
    }
  }
}

此处有更多属性:https://docs.gitlab.com/ee/api/graphql/reference/#project

实际上,您现在有一个替代解决方案,GitLab 14.7(2022 年 1 月):

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.