Skip to content
代码片段 群组 项目
未验证 提交 7d8dafa4 编辑于 作者: Tetiana Chupryna's avatar Tetiana Chupryna 提交者: GitLab
浏览文件

Merge branch 'caw-add-yard-to-workspaces-shared-contexts' into 'master'

Add YARD annotations to remote dev shared contexts

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/183440



Merged-by: default avatarTetiana Chupryna <tchupryna@gitlab.com>
Approved-by: default avatarTetiana Chupryna <tchupryna@gitlab.com>
Reviewed-by: default avatarChad Woolley <cwoolley@gitlab.com>
Co-authored-by: default avatarChad Woolley <cwoolley@gitlab.com>
No related branches found
No related tags found
2 合并请求!3031Merge per-main-jh to main-jh by luzhiyuan,!3030Merge per-main-jh to main-jh
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
} }
} }
config_to_apply = yaml_safe_load_symbolized(config_to_apply_yaml_stream) config_to_apply = yaml_safe_load_stream_symbolized(config_to_apply_yaml_stream)
config_to_apply => [ config_to_apply => [
*_, *_,
...@@ -485,9 +485,10 @@ ...@@ -485,9 +485,10 @@
# test the config to apply first to get a more specific diff if it fails # test the config to apply first to get a more specific diff if it fails
actual_workspace_rails_info = workspace_rails_infos.detect { |info| info.fetch(:name) == workspace.name } actual_workspace_rails_info = workspace_rails_infos.detect { |info| info.fetch(:name) == workspace.name }
actual_config_to_apply = yaml_safe_load_symbolized(actual_workspace_rails_info.fetch(:config_to_apply)) actual_config_to_apply =
yaml_safe_load_stream_symbolized(actual_workspace_rails_info.fetch(:config_to_apply))
expected_config_to_apply = expected_config_to_apply =
yaml_safe_load_symbolized(expected_workspace_rails_info.fetch(:config_to_apply)) yaml_safe_load_stream_symbolized(expected_workspace_rails_info.fetch(:config_to_apply))
expect(actual_config_to_apply).to eq(expected_config_to_apply) expect(actual_config_to_apply).to eq(expected_config_to_apply)
# then test everything in the infos # then test everything in the infos
......
...@@ -4,6 +4,16 @@ ...@@ -4,6 +4,16 @@
# RemoteDevelopment::WorkspaceOperations::Create::Constants, but instead hardcode the corresponding values here. # RemoteDevelopment::WorkspaceOperations::Create::Constants, but instead hardcode the corresponding values here.
RSpec.shared_context 'with remote development shared fixtures' do RSpec.shared_context 'with remote development shared fixtures' do
# rubocop:todo Metrics/ParameterLists, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity -- Cleanup as part of https://gitlab.com/gitlab-org/gitlab/-/issues/421687 # rubocop:todo Metrics/ParameterLists, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity -- Cleanup as part of https://gitlab.com/gitlab-org/gitlab/-/issues/421687
# @param [RemoteDevelopment::Workspace] workspace
# @param [String] previous_actual_state
# @param [String] current_actual_state
# @param [Boolean] workspace_exists
# @param [Hash] workspace_variables_environment
# @param [Hash] workspace_variables_file
# @param [String] resource_version
# @param [String] dns_zone
# @param [Hash] error_details
def create_workspace_agent_info_hash( def create_workspace_agent_info_hash(
workspace:, workspace:,
# NOTE: previous_actual_state is the actual state of the workspace IMMEDIATELY prior to the current state. We don't # NOTE: previous_actual_state is the actual state of the workspace IMMEDIATELY prior to the current state. We don't
...@@ -292,10 +302,16 @@ def create_workspace_agent_info_hash( ...@@ -292,10 +302,16 @@ def create_workspace_agent_info_hash(
# rubocop:enable Metrics/ParameterLists, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity # rubocop:enable Metrics/ParameterLists, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# @param [RemoteDevelopment::Workspace] workspace
# @param [Hash] args
# @return [String]
def create_config_to_apply_yaml_stream(workspace:, **args) 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 create_config_to_apply(workspace: workspace, **args).map { |resource| YAML.dump(resource.deep_stringify_keys) }.join
end end
# @param [RemoteDevelopment::Workspace] workspace
# @param [Hash] args
# @return [Array<Hash>]
def create_config_to_apply(workspace:, **args) def create_config_to_apply(workspace:, **args)
desired_config_generator_version = workspace.desired_config_generator_version desired_config_generator_version = workspace.desired_config_generator_version
...@@ -306,6 +322,28 @@ def create_config_to_apply(workspace:, **args) ...@@ -306,6 +322,28 @@ def create_config_to_apply(workspace:, **args)
end end
# rubocop:disable Metrics/ParameterLists, Metrics/AbcSize -- Cleanup as part of https://gitlab.com/gitlab-org/gitlab/-/issues/421687 # rubocop:disable Metrics/ParameterLists, Metrics/AbcSize -- Cleanup as part of https://gitlab.com/gitlab-org/gitlab/-/issues/421687
# @param [RemoteDevelopment::Workspace] workspace
# @param [Boolean] started
# @param [Hash] workspace_variables_environment
# @param [Hash] workspace_variables_file
# @param [Boolean] include_inventory
# @param [Boolean] include_network_policy
# @param [Boolean] include_all_resources
# @param [String] dns_zone
# @param [Array<Hash>] egress_ip_rules
# @param [Hash] max_resources_per_workspace
# @param [Hash] default_resources_per_workspace_container
# @param [Boolean] allow_privilege_escalation
# @param [Boolean] use_kubernetes_user_namespaces
# @param [String] default_runtime_class
# @param [Hash] agent_labels
# @param [Hash] agent_annotations
# @param [String] project_name
# @param [String] namespace_path
# @param [Array<Hash>] image_pull_secrets
# @param [Boolean] core_resources_only
# @return [Array<Hash>]
def create_config_to_apply_v3( def create_config_to_apply_v3(
workspace:, workspace:,
started:, started:,
...@@ -464,6 +502,10 @@ def create_config_to_apply_v3( ...@@ -464,6 +502,10 @@ def create_config_to_apply_v3(
# rubocop:enable Metrics/ParameterLists, Metrics/AbcSize # rubocop:enable Metrics/ParameterLists, Metrics/AbcSize
# @param [String] workspace_name
# @param [String] workspace_namespace
# @param [Integer] agent_id
# @return [Hash]
def workspace_inventory(workspace_name:, workspace_namespace:, agent_id:) def workspace_inventory(workspace_name:, workspace_namespace:, agent_id:)
{ {
kind: "ConfigMap", kind: "ConfigMap",
...@@ -481,6 +523,17 @@ def workspace_inventory(workspace_name:, workspace_namespace:, agent_id:) ...@@ -481,6 +523,17 @@ def workspace_inventory(workspace_name:, workspace_namespace:, agent_id:)
end end
# rubocop:disable Metrics/ParameterLists -- Cleanup as part of https://gitlab.com/gitlab-org/gitlab/-/issues/421687 # rubocop:disable Metrics/ParameterLists -- Cleanup as part of https://gitlab.com/gitlab-org/gitlab/-/issues/421687
# @param [String] workspace_name
# @param [String] workspace_namespace
# @param [Hash] labels
# @param [Hash] annotations
# @param [Integer] spec_replicas
# @param [Hash] default_resources_per_workspace_container
# @param [Boolean] allow_privilege_escalation
# @param [Boolean] use_kubernetes_user_namespaces
# @param [String] default_runtime_class
# @return [Hash]
def workspace_deployment( def workspace_deployment(
workspace_name:, workspace_name:,
workspace_namespace:, workspace_namespace:,
...@@ -810,6 +863,11 @@ def workspace_deployment( ...@@ -810,6 +863,11 @@ def workspace_deployment(
# rubocop:enable Metrics/ParameterLists # rubocop:enable Metrics/ParameterLists
# @param [String] workspace_name
# @param [String] workspace_namespace
# @param [Hash] labels
# @param [Hash] annotations
# @return [Hash]
def workspace_service( def workspace_service(
workspace_name:, workspace_name:,
workspace_namespace:, workspace_namespace:,
...@@ -847,6 +905,11 @@ def workspace_service( ...@@ -847,6 +905,11 @@ def workspace_service(
} }
end end
# @param [String] workspace_name
# @param [String] workspace_namespace
# @param [Hash] labels
# @param [Hash] annotations
# @return [Hash]
def workspace_pvc( def workspace_pvc(
workspace_name:, workspace_name:,
workspace_namespace:, workspace_namespace:,
...@@ -877,6 +940,12 @@ def workspace_pvc( ...@@ -877,6 +940,12 @@ def workspace_pvc(
} }
end end
# @param [String] workspace_name
# @param [String] workspace_namespace
# @param [Hash] labels
# @param [Hash] annotations
# @param [Array<Hash>] egress_ip_rules
# @return [Hash]
def workspace_network_policy( def workspace_network_policy(
workspace_name:, workspace_name:,
workspace_namespace:, workspace_namespace:,
...@@ -939,6 +1008,12 @@ def workspace_network_policy( ...@@ -939,6 +1008,12 @@ def workspace_network_policy(
} }
end end
# @param [String] workspace_name
# @param [String] workspace_namespace
# @param [Hash] labels
# @param [Hash] annotations
# @param [Hash] max_resources_per_workspace
# @return [Hash]
def workspace_resource_quota( def workspace_resource_quota(
workspace_name:, workspace_name:,
workspace_namespace:, workspace_namespace:,
...@@ -977,6 +1052,12 @@ def workspace_resource_quota( ...@@ -977,6 +1052,12 @@ def workspace_resource_quota(
} }
end end
# @param [String] name
# @param [String] namespace
# @param [Array<Hash>] image_pull_secrets
# @param [Hash] labels
# @param [Hash] annotations
# @return [Hash]
def workspace_service_account( def workspace_service_account(
name:, name:,
namespace:, namespace:,
...@@ -999,6 +1080,10 @@ def workspace_service_account( ...@@ -999,6 +1080,10 @@ def workspace_service_account(
} }
end end
# @param [String] workspace_name
# @param [String] workspace_namespace
# @param [Integer] agent_id
# @return [Hash]
def workspace_secrets_inventory( def workspace_secrets_inventory(
workspace_name:, workspace_name:,
workspace_namespace:, workspace_namespace:,
...@@ -1019,6 +1104,12 @@ def workspace_secrets_inventory( ...@@ -1019,6 +1104,12 @@ def workspace_secrets_inventory(
} }
end end
# @param [String] workspace_name
# @param [String] workspace_namespace
# @param [Hash] labels
# @param [Hash] annotations
# @param [Hash] workspace_variables_environment
# @return [Hash]
def workspace_secret_environment( def workspace_secret_environment(
workspace_name:, workspace_name:,
workspace_namespace:, workspace_namespace:,
...@@ -1040,6 +1131,12 @@ def workspace_secret_environment( ...@@ -1040,6 +1131,12 @@ def workspace_secret_environment(
} }
end end
# @param [String] workspace_name
# @param [String] workspace_namespace
# @param [Hash] labels
# @param [Hash] annotations
# @param [Hash] workspace_variables_file
# @return [Hash]
def workspace_secret_file( def workspace_secret_file(
workspace_name:, workspace_name:,
workspace_namespace:, workspace_namespace:,
...@@ -1060,6 +1157,10 @@ def workspace_secret_file( ...@@ -1060,6 +1157,10 @@ def workspace_secret_file(
} }
end end
# @param [String] namespace_path
# @param [String] project_name
# @param [Array<Hash>] resources
# @return [Array<Hash>]
def normalize_resources(namespace_path, project_name, resources) def normalize_resources(namespace_path, project_name, resources)
# Convert to YAML to normalize project_name, namespace_path, and root_url # Convert to YAML to normalize project_name, namespace_path, and root_url
normalized_resources_yaml = resources.map do |resource| normalized_resources_yaml = resources.map do |resource|
...@@ -1082,65 +1183,97 @@ def normalize_resources(namespace_path, project_name, resources) ...@@ -1082,65 +1183,97 @@ def normalize_resources(namespace_path, project_name, resources)
end end
end end
# @param [ActiveRecord::Relation] workspace_variables
# @return [Hash]
def get_workspace_variables_environment(workspace_variables:) def get_workspace_variables_environment(workspace_variables:)
workspace_variables.with_variable_type_environment.each_with_object({}) do |workspace_variable, hash| workspace_variables.with_variable_type_environment.each_with_object({}) do |workspace_variable, hash|
hash[workspace_variable.key.to_sym] = workspace_variable.value hash[workspace_variable.key.to_sym] = workspace_variable.value
end end
end end
# @param [ActiveRecord::Relation] workspace_variables
# @return [Hash]
def get_workspace_variables_file(workspace_variables:) def get_workspace_variables_file(workspace_variables:)
workspace_variables.with_variable_type_file.each_with_object({}) do |workspace_variable, hash| workspace_variables.with_variable_type_file.each_with_object({}) do |workspace_variable, hash|
hash[workspace_variable.key.to_sym] = workspace_variable.value hash[workspace_variable.key.to_sym] = workspace_variable.value
end end
end end
# @param [String] workspace_name
# @param [String] dns_zone
# @return [String]
def get_workspace_host_template_annotation(workspace_name, dns_zone) def get_workspace_host_template_annotation(workspace_name, dns_zone)
"{{.port}}-#{workspace_name}.#{dns_zone}" "{{.port}}-#{workspace_name}.#{dns_zone}"
end end
# @param [String] workspace_name
# @param [String] dns_zone
# @return [String]
def get_workspace_host_template_environment(workspace_name, dns_zone) def get_workspace_host_template_environment(workspace_name, dns_zone)
"${PORT}-#{workspace_name}.#{dns_zone}" "${PORT}-#{workspace_name}.#{dns_zone}"
end end
# @param [String] yaml
# @return [Hash]
def yaml_safe_load_symbolized(yaml) def yaml_safe_load_symbolized(yaml)
is_multiple_docs = YAML.load_stream(yaml).size > 1 raise "Use #yaml_safe_load_stream_symbolized for YAML streams (arrays)" unless YAML.load_stream(yaml).size == 1
if is_multiple_docs
YAML.load_stream(yaml).map { |doc| YAML.safe_load(YAML.dump(doc)).deep_symbolize_keys } YAML.safe_load(yaml).deep_symbolize_keys
else end
YAML.safe_load(yaml).deep_symbolize_keys
end # @param [String] yaml
# @return [Array<Hash>]
def yaml_safe_load_stream_symbolized(yaml)
raise "Use #yaml_safe_load_symbolized for YAML docs (hashes)" unless YAML.load_stream(yaml).size > 1
YAML.load_stream(yaml).map { |doc| YAML.safe_load(YAML.dump(doc)).deep_symbolize_keys }
end end
# @return [String]
def example_default_devfile_yaml def example_default_devfile_yaml
read_devfile_yaml('example.default_devfile.yaml') read_devfile_yaml('example.default_devfile.yaml')
end end
# @return [String]
def example_devfile_yaml def example_devfile_yaml
read_devfile_yaml('example.devfile.yaml') read_devfile_yaml('example.devfile.yaml')
end end
# @return [Hash]
def example_devfile def example_devfile
yaml_safe_load_symbolized(example_devfile_yaml) yaml_safe_load_symbolized(example_devfile_yaml)
end end
# @return [String]
def example_flattened_devfile_yaml def example_flattened_devfile_yaml
read_devfile_yaml("example.flattened-devfile.yaml") read_devfile_yaml("example.flattened-devfile.yaml")
end end
# @return [Hash]
def example_flattened_devfile def example_flattened_devfile
yaml_safe_load_symbolized(example_flattened_devfile_yaml) yaml_safe_load_symbolized(example_flattened_devfile_yaml)
end end
# @param [String] project_name
# @param [String] namespace_path
# @return [String]
def example_processed_devfile_yaml(project_name: "test-project", namespace_path: "test-group") def example_processed_devfile_yaml(project_name: "test-project", namespace_path: "test-group")
read_devfile_yaml("example.processed-devfile.yaml", project_name: project_name, namespace_path: namespace_path) read_devfile_yaml("example.processed-devfile.yaml", project_name: project_name, namespace_path: namespace_path)
end end
# @param [String] project_name
# @param [String] namespace_path
# @return [Hash]
def example_processed_devfile(project_name: "test-project", namespace_path: "test-group") def example_processed_devfile(project_name: "test-project", namespace_path: "test-group")
yaml_safe_load_symbolized( yaml_safe_load_symbolized(
example_processed_devfile_yaml(project_name: project_name, namespace_path: namespace_path) example_processed_devfile_yaml(project_name: project_name, namespace_path: namespace_path)
) )
end end
# @param [String] filename
# @param [String] project_name
# @param [String] namespace_path
# @return [String]
def read_devfile_yaml(filename, project_name: "test-project", namespace_path: "test-group") def read_devfile_yaml(filename, project_name: "test-project", namespace_path: "test-group")
devfile_contents = File.read(Rails.root.join('ee/spec/fixtures/remote_development', filename).to_s) devfile_contents = File.read(Rails.root.join('ee/spec/fixtures/remote_development', filename).to_s)
devfile_contents.gsub!('http://localhost/', root_url) devfile_contents.gsub!('http://localhost/', root_url)
...@@ -1149,6 +1282,7 @@ def read_devfile_yaml(filename, project_name: "test-project", namespace_path: "t ...@@ -1149,6 +1282,7 @@ def read_devfile_yaml(filename, project_name: "test-project", namespace_path: "t
devfile_contents devfile_contents
end end
# @return [String]
def root_url def root_url
# NOTE: Default to http://example.com/ if GitLab::Application is not defined. This allows this helper to be used # NOTE: Default to http://example.com/ if GitLab::Application is not defined. This allows this helper to be used
# from ee/spec/remote_development/fast_spec_helper.rb # from ee/spec/remote_development/fast_spec_helper.rb
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册