提交 b5e09a26 编写于 作者: M Mayra Cabrera 提交者: Nick Thomas

Include cluster domain into Project Cluster API

Domain was introduced on 11.8 and was not included on the
Project Cluster API. With this change user will be able to include
domain when adding and updating a cluster. Domain will also be included
on the GET calls.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/59441
上级 d8258470
---
title: Add cluster domain to Project Cluster API
merge_request: 26735
author:
type: other
...@@ -33,6 +33,7 @@ Example response: ...@@ -33,6 +33,7 @@ Example response:
{ {
"id":18, "id":18,
"name":"cluster-1", "name":"cluster-1",
"domain":"example.com",
"created_at":"2019-01-02T20:18:12.563Z", "created_at":"2019-01-02T20:18:12.563Z",
"provider_type":"user", "provider_type":"user",
"platform_type":"kubernetes", "platform_type":"kubernetes",
...@@ -90,6 +91,7 @@ Example response: ...@@ -90,6 +91,7 @@ Example response:
{ {
"id":18, "id":18,
"name":"cluster-1", "name":"cluster-1",
"domain":"example.com",
"created_at":"2019-01-02T20:18:12.563Z", "created_at":"2019-01-02T20:18:12.563Z",
"provider_type":"user", "provider_type":"user",
"platform_type":"kubernetes", "platform_type":"kubernetes",
...@@ -157,6 +159,7 @@ Parameters: ...@@ -157,6 +159,7 @@ Parameters:
| --------- | ---- | -------- | ----------- | | --------- | ---- | -------- | ----------- |
| `id` | integer | yes | The ID of the project owned by the authenticated user | | `id` | integer | yes | The ID of the project owned by the authenticated user |
| `name` | String | yes | The name of the cluster | | `name` | String | yes | The name of the cluster |
| `domain` | String | no | The [base domain](../user/project/clusters/index.md#base_domain) of the cluster |
| `enabled` | Boolean | no | Determines if cluster is active or not, defaults to true | | `enabled` | Boolean | no | Determines if cluster is active or not, defaults to true |
| `platform_kubernetes_attributes[api_url]` | String | yes | The URL to access the Kubernetes API | | `platform_kubernetes_attributes[api_url]` | String | yes | The URL to access the Kubernetes API |
| `platform_kubernetes_attributes[token]` | String | yes | The token to authenticate against Kubernetes | | `platform_kubernetes_attributes[token]` | String | yes | The token to authenticate against Kubernetes |
...@@ -247,6 +250,7 @@ Parameters: ...@@ -247,6 +250,7 @@ Parameters:
| `id` | integer | yes | The ID of the project owned by the authenticated user | | `id` | integer | yes | The ID of the project owned by the authenticated user |
| `cluster_id` | integer | yes | The ID of the cluster | | `cluster_id` | integer | yes | The ID of the cluster |
| `name` | String | no | The name of the cluster | | `name` | String | no | The name of the cluster |
| `domain` | String | no | The [base domain](../user/project/clusters/index.md#base_domain) of the cluster |
| `platform_kubernetes_attributes[api_url]` | String | no | The URL to access the Kubernetes API | | `platform_kubernetes_attributes[api_url]` | String | no | The URL to access the Kubernetes API |
| `platform_kubernetes_attributes[token]` | String | no | The token to authenticate against Kubernetes | | `platform_kubernetes_attributes[token]` | String | no | The token to authenticate against Kubernetes |
| `platform_kubernetes_attributes[ca_cert]` | String | no | TLS certificate (needed if API is using a self-signed TLS certificate | | `platform_kubernetes_attributes[ca_cert]` | String | no | TLS certificate (needed if API is using a self-signed TLS certificate |
...@@ -262,7 +266,7 @@ Example request: ...@@ -262,7 +266,7 @@ Example request:
```bash ```bash
curl --header 'Private-Token: <your_access_token>' https://gitlab.example.com/api/v4/projects/26/clusters/24 \ curl --header 'Private-Token: <your_access_token>' https://gitlab.example.com/api/v4/projects/26/clusters/24 \
-H "Content-Type:application/json" \ -H "Content-Type:application/json" \
-X PUT --data '{"name":"new-cluster-name","api_url":"https://new-api-url.com"}' -X PUT --data '{"name":"new-cluster-name","domain":"new-domain.com","api_url":"https://new-api-url.com"}'
``` ```
Example response: Example response:
...@@ -271,6 +275,7 @@ Example response: ...@@ -271,6 +275,7 @@ Example response:
{ {
"id":24, "id":24,
"name":"new-cluster-name", "name":"new-cluster-name",
"domain":"new-domain.com",
"created_at":"2019-01-03T21:53:40.610Z", "created_at":"2019-01-03T21:53:40.610Z",
"provider_type":"user", "provider_type":"user",
"platform_type":"kubernetes", "platform_type":"kubernetes",
......
...@@ -1588,7 +1588,7 @@ module API ...@@ -1588,7 +1588,7 @@ module API
end end
class Cluster < Grape::Entity class Cluster < Grape::Entity
expose :id, :name, :created_at expose :id, :name, :created_at, :domain
expose :provider_type, :platform_type, :environment_scope, :cluster_type expose :provider_type, :platform_type, :environment_scope, :cluster_type
expose :user, using: Entities::UserBasic expose :user, using: Entities::UserBasic
expose :platform_kubernetes, using: Entities::Platform::Kubernetes expose :platform_kubernetes, using: Entities::Platform::Kubernetes
......
...@@ -53,6 +53,7 @@ module API ...@@ -53,6 +53,7 @@ module API
params do params do
requires :name, type: String, desc: 'Cluster name' requires :name, type: String, desc: 'Cluster name'
optional :enabled, type: Boolean, default: true, desc: 'Determines if cluster is active or not, defaults to true' optional :enabled, type: Boolean, default: true, desc: 'Determines if cluster is active or not, defaults to true'
optional :domain, type: String, desc: 'Cluster base domain'
requires :platform_kubernetes_attributes, type: Hash, desc: %q(Platform Kubernetes data) do requires :platform_kubernetes_attributes, type: Hash, desc: %q(Platform Kubernetes data) do
requires :api_url, type: String, allow_blank: false, desc: 'URL to access the Kubernetes API' requires :api_url, type: String, allow_blank: false, desc: 'URL to access the Kubernetes API'
requires :token, type: String, desc: 'Token to authenticate against Kubernetes' requires :token, type: String, desc: 'Token to authenticate against Kubernetes'
...@@ -83,6 +84,7 @@ module API ...@@ -83,6 +84,7 @@ module API
params do params do
requires :cluster_id, type: Integer, desc: 'The cluster ID' requires :cluster_id, type: Integer, desc: 'The cluster ID'
optional :name, type: String, desc: 'Cluster name' optional :name, type: String, desc: 'Cluster name'
optional :domain, type: String, desc: 'Cluster base domain'
optional :platform_kubernetes_attributes, type: Hash, desc: %q(Platform Kubernetes data) do optional :platform_kubernetes_attributes, type: Hash, desc: %q(Platform Kubernetes data) do
optional :api_url, type: String, desc: 'URL to access the Kubernetes API' optional :api_url, type: String, desc: 'URL to access the Kubernetes API'
optional :token, type: String, desc: 'Token to authenticate against Kubernetes' optional :token, type: String, desc: 'Token to authenticate against Kubernetes'
......
...@@ -60,7 +60,7 @@ describe API::ProjectClusters do ...@@ -60,7 +60,7 @@ describe API::ProjectClusters do
end end
let(:cluster) do let(:cluster) do
create(:cluster, :project, :provided_by_gcp, create(:cluster, :project, :provided_by_gcp, :with_domain,
platform_kubernetes: platform_kubernetes, platform_kubernetes: platform_kubernetes,
user: current_user, user: current_user,
projects: [project]) projects: [project])
...@@ -88,6 +88,7 @@ describe API::ProjectClusters do ...@@ -88,6 +88,7 @@ describe API::ProjectClusters do
expect(json_response['platform_type']).to eq('kubernetes') expect(json_response['platform_type']).to eq('kubernetes')
expect(json_response['environment_scope']).to eq('*') expect(json_response['environment_scope']).to eq('*')
expect(json_response['cluster_type']).to eq('project_type') expect(json_response['cluster_type']).to eq('project_type')
expect(json_response['domain']).to eq('example.com')
end end
it 'returns project information' do it 'returns project information' do
...@@ -187,6 +188,7 @@ describe API::ProjectClusters do ...@@ -187,6 +188,7 @@ describe API::ProjectClusters do
let(:cluster_params) do let(:cluster_params) do
{ {
name: 'test-cluster', name: 'test-cluster',
domain: 'domain.example.com',
platform_kubernetes_attributes: platform_kubernetes_attributes platform_kubernetes_attributes: platform_kubernetes_attributes
} }
end end
...@@ -217,6 +219,7 @@ describe API::ProjectClusters do ...@@ -217,6 +219,7 @@ describe API::ProjectClusters do
expect(cluster_result).to be_kubernetes expect(cluster_result).to be_kubernetes
expect(cluster_result.project).to eq(project) expect(cluster_result.project).to eq(project)
expect(cluster_result.name).to eq('test-cluster') expect(cluster_result.name).to eq('test-cluster')
expect(cluster_result.domain).to eq('domain.example.com')
expect(platform_kubernetes.rbac?).to be_truthy expect(platform_kubernetes.rbac?).to be_truthy
expect(platform_kubernetes.api_url).to eq(api_url) expect(platform_kubernetes.api_url).to eq(api_url)
expect(platform_kubernetes.namespace).to eq(namespace) expect(platform_kubernetes.namespace).to eq(namespace)
...@@ -294,6 +297,7 @@ describe API::ProjectClusters do ...@@ -294,6 +297,7 @@ describe API::ProjectClusters do
let(:update_params) do let(:update_params) do
{ {
domain: 'new-domain.com',
platform_kubernetes_attributes: platform_kubernetes_attributes platform_kubernetes_attributes: platform_kubernetes_attributes
} }
end end
...@@ -330,6 +334,7 @@ describe API::ProjectClusters do ...@@ -330,6 +334,7 @@ describe API::ProjectClusters do
end end
it 'should update cluster attributes' do it 'should update cluster attributes' do
expect(cluster.domain).to eq('new-domain.com')
expect(cluster.platform_kubernetes.namespace).to eq('new-namespace') expect(cluster.platform_kubernetes.namespace).to eq('new-namespace')
end end
end end
...@@ -342,6 +347,7 @@ describe API::ProjectClusters do ...@@ -342,6 +347,7 @@ describe API::ProjectClusters do
end end
it 'should not update cluster attributes' do it 'should not update cluster attributes' do
expect(cluster.domain).not_to eq('new_domain.com')
expect(cluster.platform_kubernetes.namespace).not_to eq('invalid_namespace') expect(cluster.platform_kubernetes.namespace).not_to eq('invalid_namespace')
expect(cluster.kubernetes_namespace.namespace).not_to eq('invalid_namespace') expect(cluster.kubernetes_namespace.namespace).not_to eq('invalid_namespace')
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册