Commit aae65bb2 authored by Tiger's avatar Tiger

Enable agent registration UI

https://gitlab.com/gitlab-org/gitlab/-/merge_requests/63718

Changelog: added
EE: true
parent 56bde216
...@@ -24,7 +24,8 @@ module ClustersHelper ...@@ -24,7 +24,8 @@ module ClustersHelper
agent_docs_url: help_page_path('user/clusters/agent/index'), agent_docs_url: help_page_path('user/clusters/agent/index'),
install_docs_url: help_page_path('administration/clusters/kas'), install_docs_url: help_page_path('administration/clusters/kas'),
get_started_docs_url: help_page_path('user/clusters/agent/index', anchor: 'define-a-configuration-repository'), get_started_docs_url: help_page_path('user/clusters/agent/index', anchor: 'define-a-configuration-repository'),
integration_docs_url: help_page_path('user/clusters/agent/index', anchor: 'get-started-with-gitops-and-the-gitlab-agent') integration_docs_url: help_page_path('user/clusters/agent/index', anchor: 'get-started-with-gitops-and-the-gitlab-agent'),
kas_address: Gitlab::Kas.external_url
} }
end end
......
<script> <script>
import { GlButton, GlEmptyState, GlLink, GlSprintf, GlAlert } from '@gitlab/ui'; import { GlButton, GlEmptyState, GlLink, GlSprintf, GlAlert, GlModalDirective } from '@gitlab/ui';
import { INSTALL_AGENT_MODAL_ID } from '../constants';
export default { export default {
modalId: INSTALL_AGENT_MODAL_ID,
components: { components: {
GlButton, GlButton,
GlEmptyState, GlEmptyState,
...@@ -9,6 +11,9 @@ export default { ...@@ -9,6 +11,9 @@ export default {
GlSprintf, GlSprintf,
GlAlert, GlAlert,
}, },
directives: {
GlModalDirective,
},
inject: [ inject: [
'emptyStateImage', 'emptyStateImage',
'projectPath', 'projectPath',
...@@ -101,12 +106,11 @@ export default { ...@@ -101,12 +106,11 @@ export default {
<template #actions> <template #actions>
<gl-button <gl-button
v-gl-modal-directive="$options.modalId"
:disabled="!hasConfigurations" :disabled="!hasConfigurations"
data-testid="integration-primary-button" data-testid="integration-primary-button"
category="primary" category="primary"
variant="success" variant="success"
:href="integrationDocsUrl"
target="_blank"
> >
{{ s__('ClusterAgents|Integrate with the GitLab Agent') }} {{ s__('ClusterAgents|Integrate with the GitLab Agent') }}
</gl-button> </gl-button>
......
<script> <script>
import { GlLink, GlTable } from '@gitlab/ui'; import { GlButton, GlLink, GlModalDirective, GlTable } from '@gitlab/ui';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import { INSTALL_AGENT_MODAL_ID } from '../constants';
export default { export default {
modalId: INSTALL_AGENT_MODAL_ID,
components: { components: {
GlButton,
GlLink, GlLink,
GlTable, GlTable,
}, },
directives: {
GlModalDirective,
},
inject: ['integrationDocsUrl'], inject: ['integrationDocsUrl'],
props: { props: {
agents: { agents: {
...@@ -34,9 +40,9 @@ export default { ...@@ -34,9 +40,9 @@ export default {
<template> <template>
<div> <div>
<div class="gl-display-block gl-text-right gl-my-3"> <div class="gl-display-block gl-text-right gl-my-3">
<gl-link :href="integrationDocsUrl" target="_blank"> <gl-button v-gl-modal-directive="$options.modalId" variant="success" category="primary"
{{ s__('ClusterAgents|Learn more about installing the GitLab Agent') }} >{{ s__('ClusterAgents|Install a new GitLab Agent') }}
</gl-link> </gl-button>
</div> </div>
<gl-table :items="agents" :fields="fields" stacked="md" data-testid="cluster-agent-list-table"> <gl-table :items="agents" :fields="fields" stacked="md" data-testid="cluster-agent-list-table">
......
...@@ -4,6 +4,7 @@ import { MAX_LIST_COUNT } from '../constants'; ...@@ -4,6 +4,7 @@ import { MAX_LIST_COUNT } from '../constants';
import getAgentsQuery from '../graphql/queries/get_agents.query.graphql'; import getAgentsQuery from '../graphql/queries/get_agents.query.graphql';
import AgentEmptyState from './agent_empty_state.vue'; import AgentEmptyState from './agent_empty_state.vue';
import AgentTable from './agent_table.vue'; import AgentTable from './agent_table.vue';
import InstallAgentModal from './install_agent_modal.vue';
export default { export default {
apollo: { apollo: {
...@@ -25,6 +26,7 @@ export default { ...@@ -25,6 +26,7 @@ export default {
components: { components: {
AgentEmptyState, AgentEmptyState,
AgentTable, AgentTable,
InstallAgentModal,
GlAlert, GlAlert,
GlKeysetPagination, GlKeysetPagination,
GlLoadingIcon, GlLoadingIcon,
...@@ -76,6 +78,9 @@ export default { ...@@ -76,6 +78,9 @@ export default {
}, },
}, },
methods: { methods: {
reloadAgents() {
this.$apollo.queries.agents.refetch();
},
nextPage() { nextPage() {
this.cursor = { this.cursor = {
first: MAX_LIST_COUNT, first: MAX_LIST_COUNT,
...@@ -118,6 +123,7 @@ export default { ...@@ -118,6 +123,7 @@ export default {
</div> </div>
<AgentEmptyState v-else :has-configurations="hasConfigurations" /> <AgentEmptyState v-else :has-configurations="hasConfigurations" />
<InstallAgentModal @agentRegistered="reloadAgents" />
</section> </section>
<gl-alert v-else variant="danger" :dismissible="false"> <gl-alert v-else variant="danger" :dismissible="false">
......
...@@ -18,6 +18,7 @@ export default (Vue, VueApollo) => { ...@@ -18,6 +18,7 @@ export default (Vue, VueApollo) => {
installDocsUrl, installDocsUrl,
getStartedDocsUrl, getStartedDocsUrl,
integrationDocsUrl, integrationDocsUrl,
kasAddress,
} = el.dataset; } = el.dataset;
return new Vue({ return new Vue({
...@@ -30,6 +31,7 @@ export default (Vue, VueApollo) => { ...@@ -30,6 +31,7 @@ export default (Vue, VueApollo) => {
installDocsUrl, installDocsUrl,
getStartedDocsUrl, getStartedDocsUrl,
integrationDocsUrl, integrationDocsUrl,
kasAddress,
}, },
render(createElement) { render(createElement) {
return createElement(Agents, { return createElement(Agents, {
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Cluster agent registration', :js do
let_it_be(:project) { create(:project, :custom_repo, files: { '.gitlab/agents/example-agent-1/config.yaml' => '' }) }
let_it_be(:current_user) { create(:user, maintainer_projects: [project]) }
before do
stub_licensed_features(cluster_agents: true)
allow(Gitlab::Kas).to receive(:enabled?).and_return(true)
allow(Gitlab::Kas).to receive(:internal_url).and_return('kas.example.internal')
allow_next_instance_of(Gitlab::Kas::Client) do |client|
allow(client).to receive(:list_agent_config_files).and_return([
double(agent_name: 'example-agent-1', path: '.gitlab/agents/example-agent-1/config.yaml'),
double(agent_name: 'example-agent-2', path: '.gitlab/agents/example-agent-2/config.yaml')
])
end
allow(Devise).to receive(:friendly_token).and_return('example-agent-token')
sign_in(current_user)
visit project_clusters_path(project)
end
it 'allows the user to select an agent to install, and displays the resulting agent token' do
click_link('GitLab Agent managed clusters')
click_button('Integrate with the GitLab Agent')
expect(page).to have_content('Install new Agent')
click_button('Select an Agent')
click_button('example-agent-2')
click_button('Next')
expect(page).to have_content('The token value will not be shown again after you close this window.')
expect(page).to have_content('example-agent-token')
expect(page).to have_content('docker run --pull=always --rm')
click_button('Done')
expect(page).to have_link('example-agent-2')
expect(page).to have_no_content('Install new Agent')
end
end
...@@ -57,7 +57,7 @@ RSpec.describe 'ClusterAgents', :js do ...@@ -57,7 +57,7 @@ RSpec.describe 'ClusterAgents', :js do
it 'displays empty state', :aggregate_failures do it 'displays empty state', :aggregate_failures do
click_link 'GitLab Agent managed clusters' click_link 'GitLab Agent managed clusters'
expect(page).to have_link('Integrate with the GitLab Agent') expect(page).to have_content('Integrate with the GitLab Agent')
expect(page).to have_selector('.empty-state') expect(page).to have_selector('.empty-state')
end end
end end
......
...@@ -73,9 +73,5 @@ describe('AgentEmptyStateComponent', () => { ...@@ -73,9 +73,5 @@ describe('AgentEmptyStateComponent', () => {
expect(findConfigurationsAlert().exists()).toBe(false); expect(findConfigurationsAlert().exists()).toBe(false);
expect(findIntegrationButton().attributes('disabled')).toBeUndefined(); expect(findIntegrationButton().attributes('disabled')).toBeUndefined();
}); });
it('should render correct href for the integration button', () => {
expect(findIntegrationButton().attributes('href')).toBe(integrationDocsUrl);
});
}); });
}); });
import { GlLink } from '@gitlab/ui'; import { GlButton, GlLink } from '@gitlab/ui';
import { mount } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
import AgentTable from 'ee/clusters_list/components/agent_table.vue'; import AgentTable from 'ee/clusters_list/components/agent_table.vue';
...@@ -33,9 +33,8 @@ describe('AgentTable', () => { ...@@ -33,9 +33,8 @@ describe('AgentTable', () => {
} }
}); });
it('displays header link with the correct href', () => { it('displays header button', () => {
expect(wrapper.find(GlLink).text()).toBe('Learn more about installing the GitLab Agent'); expect(wrapper.find(GlButton).text()).toBe('Install a new GitLab Agent');
expect(wrapper.find(GlLink).attributes('href')).toBe('path/to/integrationDocs');
}); });
describe('agent table', () => { describe('agent table', () => {
......
...@@ -18,6 +18,7 @@ describe('Agents', () => { ...@@ -18,6 +18,7 @@ describe('Agents', () => {
}; };
const provideData = { const provideData = {
projectPath: 'path/to/project', projectPath: 'path/to/project',
kasAddress: 'kas.example.com',
}; };
const createWrapper = ({ agents = [], pageInfo = null, trees = [] }) => { const createWrapper = ({ agents = [], pageInfo = null, trees = [] }) => {
......
...@@ -7165,6 +7165,9 @@ msgstr "" ...@@ -7165,6 +7165,9 @@ msgstr ""
msgid "ClusterAgents|Go to the repository" msgid "ClusterAgents|Go to the repository"
msgstr "" msgstr ""
msgid "ClusterAgents|Install a new GitLab Agent"
msgstr ""
msgid "ClusterAgents|Install new Agent" msgid "ClusterAgents|Install new Agent"
msgstr "" msgstr ""
...@@ -7180,9 +7183,6 @@ msgstr "" ...@@ -7180,9 +7183,6 @@ msgstr ""
msgid "ClusterAgents|Learn how to create an agent access token" msgid "ClusterAgents|Learn how to create an agent access token"
msgstr "" msgstr ""
msgid "ClusterAgents|Learn more about installing the GitLab Agent"
msgstr ""
msgid "ClusterAgents|Name" msgid "ClusterAgents|Name"
msgstr "" msgstr ""
......
...@@ -82,6 +82,10 @@ RSpec.describe ClustersHelper do ...@@ -82,6 +82,10 @@ RSpec.describe ClustersHelper do
expect(subject[:get_started_docs_url]).to eq(help_page_path('user/clusters/agent/index', anchor: 'define-a-configuration-repository')) expect(subject[:get_started_docs_url]).to eq(help_page_path('user/clusters/agent/index', anchor: 'define-a-configuration-repository'))
expect(subject[:integration_docs_url]).to eq(help_page_path('user/clusters/agent/index', anchor: 'get-started-with-gitops-and-the-gitlab-agent')) expect(subject[:integration_docs_url]).to eq(help_page_path('user/clusters/agent/index', anchor: 'get-started-with-gitops-and-the-gitlab-agent'))
end end
it 'displays kas address' do
expect(subject[:kas_address]).to eq(Gitlab::Kas.external_url)
end
end end
describe '#js_clusters_list_data' do describe '#js_clusters_list_data' do
......
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