From 1965367f1ad75f5e49246f84617f55ed74a8e9e4 Mon Sep 17 00:00:00 2001 From: Ashvin Sharma Date: Wed, 11 Jun 2025 16:29:26 +0530 Subject: [PATCH] Remove DesiredConfigGenerator versioned call From response_payload_builder.rb Versioning is removed from DesiredConfigGenerator in favor of freezing kubernetes config during the create step of workspace. As a result this code is not needed anymore. Older workspaces will use the config that is already generated for them when they were created thereby eliminating the need for the DesiredConfigGenerator to be versioned. The version column and other model related changes will be done in a separate MR later. --- .../output/response_payload_builder.rb | 24 +++----------- .../output/response_payload_builder_spec.rb | 32 ------------------- .../remote_development_shared_contexts.rb | 25 ++++++--------- 3 files changed, 15 insertions(+), 66 deletions(-) diff --git a/ee/lib/remote_development/workspace_operations/reconcile/output/response_payload_builder.rb b/ee/lib/remote_development/workspace_operations/reconcile/output/response_payload_builder.rb index 339d904b1c2d6b..522b1da136a332 100644 --- a/ee/lib/remote_development/workspace_operations/reconcile/output/response_payload_builder.rb +++ b/ee/lib/remote_development/workspace_operations/reconcile/output/response_payload_builder.rb @@ -84,25 +84,11 @@ def self.generate_config_to_apply(workspace:, update_type:, logger:) include_all_resources = should_include_all_resources?(update_type: update_type, workspace: workspace) resources_include_type = include_all_resources ? ALL_RESOURCES_INCLUDED : PARTIAL_RESOURCES_INCLUDED - workspace_resources = - case workspace.desired_config_generator_version - when DesiredConfigGeneratorVersion::LATEST_VERSION - DesiredConfigGenerator.generate_desired_config( - workspace: workspace, - include_all_resources: include_all_resources, - logger: logger - ) - else - namespace = "RemoteDevelopment::WorkspaceOperations::Reconcile::Output" - generator_class_name = - "#{namespace}::DesiredConfigGeneratorV#{workspace.desired_config_generator_version}" - generator_class = Object.const_get(generator_class_name, false) - generator_class.generate_desired_config( - workspace: workspace, - include_all_resources: include_all_resources, - logger: logger - ) - end + workspace_resources = DesiredConfigGenerator.generate_desired_config( + workspace: workspace, + include_all_resources: include_all_resources, + logger: logger + ) stable_sorted_workspace_resources = workspace_resources.map do |resource| Gitlab::Utils.deep_sort_hash(resource) diff --git a/ee/spec/lib/remote_development/workspace_operations/reconcile/output/response_payload_builder_spec.rb b/ee/spec/lib/remote_development/workspace_operations/reconcile/output/response_payload_builder_spec.rb index 6f5fb513a8e21b..edb91d14748c1d 100644 --- a/ee/spec/lib/remote_development/workspace_operations/reconcile/output/response_payload_builder_spec.rb +++ b/ee/spec/lib/remote_development/workspace_operations/reconcile/output/response_payload_builder_spec.rb @@ -222,36 +222,4 @@ end end end - - context "when workspace.desired_config_generator_version is a previous version" do - let(:previous_desired_config_generator_version) { 2 } - - let(:desired_config_generator_version) { previous_desired_config_generator_version } - let(:update_type) { update_types::FULL } - let(:desired_state_updated_more_recently_than_last_response_to_agent) { false } - let(:actual_state_updated_more_recently_than_last_response_to_agent) { false } - let(:desired_state_terminated_and_actual_state_not_terminated) { false } - let(:expected_include_all_resources) { true } - - before do - stub_const( - "RemoteDevelopment::WorkspaceOperations::Reconcile::Output::DesiredConfigGeneratorV2", - Class.new do - # @param [Object] _ - # @return [Hash] - def self.generate_desired_config(_) - {} - end - end - ) - end - - it "includes config_to_apply with all resources included" do - # noinspection RubyResolve -- This constant is stubbed - allow(RemoteDevelopment::WorkspaceOperations::Reconcile::Output::DesiredConfigGeneratorV2) - .to(receive(:generate_desired_config)) { generated_config_to_apply } - - expect(returned_value).to eq(expected_returned_value) - end - end end diff --git a/ee/spec/support/shared_contexts/remote_development/remote_development_shared_contexts.rb b/ee/spec/support/shared_contexts/remote_development/remote_development_shared_contexts.rb index 5d667ba17665aa..e9a23e44b2c107 100644 --- a/ee/spec/support/shared_contexts/remote_development/remote_development_shared_contexts.rb +++ b/ee/spec/support/shared_contexts/remote_development/remote_development_shared_contexts.rb @@ -322,20 +322,6 @@ def create_config_to_apply_yaml_stream(workspace:, **args) create_config_to_apply(workspace: workspace, **args).map { |resource| YAML.dump(resource.deep_stringify_keys) }.join end - # @param [RemoteDevelopment::Workspace] workspace - # @param [Hash] args - # @return [Array] - def create_config_to_apply(workspace:, **args) - validate_hash_is_deep_symbolized(args) - - desired_config_generator_version = workspace.desired_config_generator_version - - method_name = "create_config_to_apply_v#{desired_config_generator_version}" - # rubocop:disable GitlabSecurity/PublicSend -- We are intentionally doing this send to dynamically select the generator version method - send(method_name, workspace: workspace, **args) - # rubocop:enable GitlabSecurity/PublicSend - end - # rubocop:disable Metrics/ParameterLists, Metrics/AbcSize, Metrics/PerceivedComplexity -- Cleanup as part of https://gitlab.com/gitlab-org/gitlab/-/issues/421687 # @param [RemoteDevelopment::Workspace] workspace @@ -366,7 +352,7 @@ def create_config_to_apply(workspace:, **args) # @param [String] shared_namespace # @param [Boolean] core_resources_only # @return [Array] - def create_config_to_apply_v3( + def create_config_to_apply( workspace:, started: true, desired_state_is_terminated: false, @@ -398,6 +384,15 @@ def create_config_to_apply_v3( shared_namespace: "", core_resources_only: false ) + all_parameters = + method(__method__.to_s) + .parameters + .map(&:last) + .index_with { |name| binding.local_variable_get(name) } + .to_h + + validate_hash_is_deep_symbolized(all_parameters) + spec_replicas = started ? 1 : 0 host_template_annotation = get_workspace_host_template_annotation(workspace.name, dns_zone) -- GitLab