Commit 77d5de5b authored by Dylan Griffith's avatar Dylan Griffith

EE: Add API for CRUD group clusters

This is basically a copy of the API for project clusters.
parent 78cf7132
# frozen_string_literal: true
module EE
module API
module GroupClusters
extend ActiveSupport::Concern
prepended do
helpers do
params :create_params_ee do
optional :environment_scope, default: '*', type: String, desc: 'The associated environment to the cluster'
end
params :update_params_ee do
optional :environment_scope, type: String, desc: 'The associated environment to the cluster'
end
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe API::GroupClusters do
include KubernetesHelpers
let(:current_user) { create(:user) }
let(:group) { create(:group) }
before do
group.add_maintainer(current_user)
end
describe 'POST /groups/:id/clusters/user' do
let(:api_url) { 'https://kubernetes.example.com' }
let(:platform_kubernetes_attributes) do
{
api_url: api_url,
token: 'sample-token'
}
end
let(:cluster_params) do
{
name: 'test-cluster',
environment_scope: 'production/*',
platform_kubernetes_attributes: platform_kubernetes_attributes
}
end
context 'when user sets specific environment scope' do
it 'creates a cluster with that specific environment' do
post api("/groups/#{group.id}/clusters/user", current_user), params: cluster_params
expect(json_response['environment_scope']).to eq('production/*')
end
end
context 'when does not set an specific environment scope' do
let(:cluster_params) do
{
name: 'test-cluster',
platform_kubernetes_attributes: platform_kubernetes_attributes
}
end
it 'sets default environment' do
post api("/groups/#{group.id}/clusters/user", current_user), params: cluster_params
expect(json_response['environment_scope']).to eq('*')
end
end
context 'when license has multiple clusters feature' do
before do
stub_licensed_features(multiple_clusters: true)
create(:cluster, :provided_by_gcp, :group,
groups: [group])
post api("/groups/#{group.id}/clusters/user", current_user), params: cluster_params
end
it 'responds with 201' do
expect(response).to have_gitlab_http_status(201)
end
it 'allows multiple clusters to be associated to group' do
expect(group.reload.clusters.count).to eq(2)
end
end
end
describe 'PUT /groups/:id/clusters/:cluster_id' do
let(:api_url) { 'https://kubernetes.example.com' }
let(:update_params) do
{
environment_scope: 'test/*'
}
end
before do
put api("/groups/#{group.id}/clusters/#{cluster.id}", current_user), params: update_params
cluster.reload
end
context 'With a GCP cluster' do
let(:cluster) do
create(:cluster, :group, :provided_by_gcp,
groups: [group])
end
it 'updates the environment scope' do
expect(cluster.environment_scope).to eq('test/*')
end
end
context 'With an user cluster' do
let(:cluster) do
create(:cluster, :group, :provided_by_user,
groups: [group])
end
it 'updates the environment scope' do
expect(cluster.environment_scope).to eq('test/*')
end
end
end
end
......@@ -16,6 +16,8 @@ module API
end
end
prepend EE::API::GroupClusters # rubocop: disable Cop/InjectEnterpriseEditionModule
params do
requires :id, type: String, desc: 'The ID of the group'
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment