Skip to content

Support Cluster Agent ID in Environment Update mutation

This MR is based on Add cluster_agent_id FK to environments (!120954 - merged)

What does this MR do and why?

Support Cluster Agent ID in Environment Update mutation

This commit allows users to set Cluster Agent ID to an existing environment.

Related to Allow to Select Agent in Environment setting page (#396407 - closed)

Mutation request examples

Set an cluster to an environment

GraphQL Mutation request

mutation {
  environmentUpdate(input: { id: "gid://gitlab/Environment/17",
      clusterAgentId: "gid://gitlab/Clusters::Agent/2"
    }) {
    environment {
      name
    }
    errors
  }
}

Response

{
  "data": {
    "environmentUpdate": {
      "environment": {
        "name": "production"
      },
      "errors": []
    }
  }
}

Internal state

[11] pry(main)> project.environments.last.cluster_agent
=> #<Clusters::Agent:0x00007f0392051eb8
 id: 2,
 created_at: Tue, 16 May 2023 02:51:05.154548000 UTC +00:00,
 updated_at: Tue, 16 May 2023 02:51:05.154548000 UTC +00:00,
 project_id: 20,
 name: "prod",
 created_by_user_id: 1,
 has_vulnerabilities: false>
Unset an cluster from an environment

GraphQL Mutation request

mutation {
  environmentUpdate(input: { id: "gid://gitlab/Environment/17",
      clusterAgentId: null
    }) {
    environment {
      name
    }
    errors
  }
}

Response

{
  "data": {
    "environmentUpdate": {
      "environment": {
        "name": "production"
      },
      "errors": []
    }
  }
}

Internal state

[12] pry(main)> project.environments.last.cluster_agent
=> nil

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Shinya Maeda

Merge request reports

Loading