From 4126d17272071f4fc4bf5e741217713397ec31c0 Mon Sep 17 00:00:00 2001 From: Zhaochen Li Date: Tue, 1 Jul 2025 15:26:55 +1000 Subject: [PATCH 1/3] Handle agent config not found gracefully --- ee/lib/ee/api/internal/kubernetes.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ee/lib/ee/api/internal/kubernetes.rb b/ee/lib/ee/api/internal/kubernetes.rb index d4481f325aa503..e4e4edbd87cc3e 100644 --- a/ee/lib/ee/api/internal/kubernetes.rb +++ b/ee/lib/ee/api/internal/kubernetes.rb @@ -87,6 +87,13 @@ def update_configuration(agent:, config:) agent: agent } + unless agent.unversioned_latest_workspaces_agent_config + not_acceptable!( + 'The remote development workspaces config for the agent is invalid. ' \ + 'Please see https://docs.gitlab.com/user/workspace/settings/#configuration-reference' + ) + end + response = ::RemoteDevelopment::CommonService.execute( domain_main_class: ::RemoteDevelopment::AgentPrerequisitesOperations::Main, domain_main_class_args: domain_main_class_args -- GitLab From b397c5642780ca5647e743ce6a8c274993ca3eac Mon Sep 17 00:00:00 2001 From: Zhaochen Li Date: Tue, 1 Jul 2025 15:34:12 +1000 Subject: [PATCH 2/3] Lift the check above args --- ee/lib/ee/api/internal/kubernetes.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ee/lib/ee/api/internal/kubernetes.rb b/ee/lib/ee/api/internal/kubernetes.rb index e4e4edbd87cc3e..a097058ced86b2 100644 --- a/ee/lib/ee/api/internal/kubernetes.rb +++ b/ee/lib/ee/api/internal/kubernetes.rb @@ -83,10 +83,6 @@ def update_configuration(agent:, config:) forbidden!('"remote_development" licensed feature is not available') end - domain_main_class_args = { - agent: agent - } - unless agent.unversioned_latest_workspaces_agent_config not_acceptable!( 'The remote development workspaces config for the agent is invalid. ' \ @@ -94,6 +90,10 @@ def update_configuration(agent:, config:) ) end + domain_main_class_args = { + agent: agent + } + response = ::RemoteDevelopment::CommonService.execute( domain_main_class: ::RemoteDevelopment::AgentPrerequisitesOperations::Main, domain_main_class_args: domain_main_class_args -- GitLab From 1c50456b2bd9db6b0160088fe627182b2d83287d Mon Sep 17 00:00:00 2001 From: Zhaochen Li Date: Tue, 1 Jul 2025 16:24:59 +1000 Subject: [PATCH 3/3] Fix rspec --- ee/lib/ee/api/internal/kubernetes.rb | 5 +++-- .../requests/api/internal/kubernetes_spec.rb | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/ee/lib/ee/api/internal/kubernetes.rb b/ee/lib/ee/api/internal/kubernetes.rb index a097058ced86b2..08bc8919105d88 100644 --- a/ee/lib/ee/api/internal/kubernetes.rb +++ b/ee/lib/ee/api/internal/kubernetes.rb @@ -84,9 +84,10 @@ def update_configuration(agent:, config:) end unless agent.unversioned_latest_workspaces_agent_config - not_acceptable!( + render_api_error!( 'The remote development workspaces config for the agent is invalid. ' \ - 'Please see https://docs.gitlab.com/user/workspace/settings/#configuration-reference' + 'Please see https://docs.gitlab.com/user/workspace/settings/#configuration-reference', + 406 ) end diff --git a/ee/spec/requests/api/internal/kubernetes_spec.rb b/ee/spec/requests/api/internal/kubernetes_spec.rb index 5905e8b9a3dd18..6bac5ac7de937c 100644 --- a/ee/spec/requests/api/internal/kubernetes_spec.rb +++ b/ee/spec/requests/api/internal/kubernetes_spec.rb @@ -145,6 +145,9 @@ def send_request(params: {}, headers: agent_token_headers) before do stub_licensed_features(remote_development: true) + # rubocop:disable RSpec/AnyInstanceOf -- It's NOT the next instance... + allow_any_instance_of(Clusters::Agent).to receive(:unversioned_latest_workspaces_agent_config).and_return(true) + # rubocop:enable RSpec/AnyInstanceOf end include_examples 'authorization' @@ -179,6 +182,22 @@ def send_request(params: {}, headers: agent_token_headers) end end + context 'when agent config not found' do + before do + # rubocop:disable RSpec/AnyInstanceOf -- It's NOT the next instance... + allow_any_instance_of(Clusters::Agent).to receive(:unversioned_latest_workspaces_agent_config).and_return(nil) + # rubocop:enable RSpec/AnyInstanceOf + end + + it 'returns service response with error 406' do + expect(RemoteDevelopment::CommonService).not_to receive(:execute) + + send_request + + expect(response).to have_gitlab_http_status(:not_acceptable) + end + end + context 'when remote_development feature is unlicensed' do before do stub_licensed_features(remote_development: false) -- GitLab