Commit 2b78fc45 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'mc/bug/fix-k8s-docker-runner-setup' into 'master'

Make register_instructions optional in RunnerSetup

See merge request gitlab-org/gitlab!47123
parents e2f4a758 68676776
...@@ -27,7 +27,7 @@ module Resolvers ...@@ -27,7 +27,7 @@ module Resolvers
) )
{ {
install_instructions: instructions.install_script, install_instructions: instructions.install_script || other_install_instructions(platform),
register_instructions: instructions.register_command register_instructions: instructions.register_command
} }
ensure ensure
...@@ -36,6 +36,10 @@ module Resolvers ...@@ -36,6 +36,10 @@ module Resolvers
private private
def other_install_instructions(platform)
Gitlab::Ci::RunnerInstructions::OTHER_ENVIRONMENTS[platform.to_sym][:installation_instructions_url]
end
def target_param(args) def target_param(args)
project_param(args[:project_id]) || group_param(args[:group_id]) || {} project_param(args[:project_id]) || group_param(args[:group_id]) || {}
end end
......
...@@ -8,7 +8,7 @@ module Types ...@@ -8,7 +8,7 @@ module Types
field :install_instructions, GraphQL::STRING_TYPE, null: false, field :install_instructions, GraphQL::STRING_TYPE, null: false,
description: 'Instructions for installing the runner on the specified architecture' description: 'Instructions for installing the runner on the specified architecture'
field :register_instructions, GraphQL::STRING_TYPE, null: false, field :register_instructions, GraphQL::STRING_TYPE, null: true,
description: 'Instructions for registering the runner' description: 'Instructions for registering the runner'
end end
end end
......
---
title: Make register_instructions optional for RunnerSetup.
merge_request: 47123
author:
type: fixed
...@@ -18411,7 +18411,7 @@ type RunnerSetup { ...@@ -18411,7 +18411,7 @@ type RunnerSetup {
""" """
Instructions for registering the runner Instructions for registering the runner
""" """
registerInstructions: String! registerInstructions: String
} }
""" """
......
...@@ -53211,13 +53211,9 @@ ...@@ -53211,13 +53211,9 @@
], ],
"type": { "type": {
"kind": "NON_NULL", "kind": "SCALAR",
"name": null, "name": "String",
"ofType": { "ofType": null
"kind": "SCALAR",
"name": "String",
"ofType": null
}
}, },
"isDeprecated": false, "isDeprecated": false,
"deprecationReason": null "deprecationReason": null
...@@ -2617,7 +2617,7 @@ Autogenerated return type of RunDASTScan. ...@@ -2617,7 +2617,7 @@ Autogenerated return type of RunDASTScan.
| Field | Type | Description | | Field | Type | Description |
| ----- | ---- | ----------- | | ----- | ---- | ----------- |
| `installInstructions` | String! | Instructions for installing the runner on the specified architecture | | `installInstructions` | String! | Instructions for installing the runner on the specified architecture |
| `registerInstructions` | String! | Instructions for registering the runner | | `registerInstructions` | String | Instructions for registering the runner |
### SastCiConfiguration ### SastCiConfiguration
......
...@@ -8,77 +8,95 @@ RSpec.describe Resolvers::Ci::RunnerSetupResolver do ...@@ -8,77 +8,95 @@ RSpec.describe Resolvers::Ci::RunnerSetupResolver do
describe '#resolve' do describe '#resolve' do
let(:user) { create(:user) } let(:user) { create(:user) }
subject(:resolve_subject) { resolve(described_class, ctx: { current_user: user }, args: { platform: 'linux', architecture: 'amd64' }.merge(target_param)) } subject(:resolve_subject) { resolve(described_class, ctx: { current_user: user }, args: { platform: platform, architecture: 'amd64' }.merge(target_param)) }
context 'without target parameter' do context 'with container platforms' do
let(:target_param) { {} } let(:platform) { 'docker' }
let(:project) { create(:project) }
let(:target_param) { { project_id: project.to_global_id } }
context 'when user is not admin' do it 'returns install instructions' do
it 'returns access error' do expect(resolve_subject[:install_instructions]).not_to eq(nil)
expect { resolve_subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
end
end end
context 'when user is admin' do it 'does not return register instructions' do
before do expect(resolve_subject[:register_instructions]).to eq(nil)
user.update!(admin: true)
end
it 'returns install and register instructions' do
expect(resolve_subject.keys).to contain_exactly(:install_instructions, :register_instructions)
expect(resolve_subject.values).not_to include(nil)
end
end end
end end
context 'with project target parameter' do context 'with regular platforms' do
let(:project) { create(:project) } let(:platform) { 'linux' }
let(:target_param) { { project_id: project.to_global_id } }
context 'when user has access to admin builds on project' do context 'without target parameter' do
before do let(:target_param) { {} }
project.add_maintainer(user)
end
it 'returns install and register instructions' do context 'when user is not admin' do
expect(resolve_subject.keys).to contain_exactly(:install_instructions, :register_instructions) it 'returns access error' do
expect(resolve_subject.values).not_to include(nil) expect { resolve_subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
end
end end
end
context 'when user does not have access to admin builds on project' do context 'when user is admin' do
before do before do
project.add_developer(user) user.update!(admin: true)
end end
it 'returns access error' do it 'returns install and register instructions' do
expect { resolve_subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) expect(resolve_subject.keys).to contain_exactly(:install_instructions, :register_instructions)
expect(resolve_subject.values).not_to include(nil)
end
end end
end end
end
context 'with group target parameter' do context 'with project target parameter' do
let(:group) { create(:group) } let(:project) { create(:project) }
let(:target_param) { { group_id: group.to_global_id } } let(:target_param) { { project_id: project.to_global_id } }
context 'when user has access to admin builds on project' do
before do
project.add_maintainer(user)
end
context 'when user has access to admin builds on group' do it 'returns install and register instructions' do
before do expect(resolve_subject.keys).to contain_exactly(:install_instructions, :register_instructions)
group.add_owner(user) expect(resolve_subject.values).not_to include(nil)
end
end end
it 'returns install and register instructions' do context 'when user does not have access to admin builds on project' do
expect(resolve_subject.keys).to contain_exactly(:install_instructions, :register_instructions) before do
expect(resolve_subject.values).not_to include(nil) project.add_developer(user)
end
it 'returns access error' do
expect { resolve_subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
end
end end
end end
context 'when user does not have access to admin builds on group' do context 'with group target parameter' do
before do let(:group) { create(:group) }
group.add_developer(user) let(:target_param) { { group_id: group.to_global_id } }
context 'when user has access to admin builds on group' do
before do
group.add_owner(user)
end
it 'returns install and register instructions' do
expect(resolve_subject.keys).to contain_exactly(:install_instructions, :register_instructions)
expect(resolve_subject.values).not_to include(nil)
end
end end
it 'returns access error' do context 'when user does not have access to admin builds on group' do
expect { resolve_subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) before do
group.add_developer(user)
end
it 'returns access error' do
expect { resolve_subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
end
end end
end end
end 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