From 8e30994e06d522a99cf21ed2487abeb701c511b6 Mon Sep 17 00:00:00 2001 From: Chad Woolley Date: Wed, 4 Dec 2024 17:52:52 +0530 Subject: [PATCH 1/2] Refactor workspace devfile logic/spec/fixtures - Second preliminary refactoring/rename/cleanup to prepare for https://gitlab.com/gitlab-org/gitlab/-/issues/505988 - Default all top-level structures in flattened devfile in initial devfile_flattener, instead of initializing them lazily in subsequent steps - Rename and refactor some fixture files - Refactor read_devfile_* methods to read_devfile_*_yaml - converting devfile processing keys to symbols for easier reference, and ability to use rightward-assignment destructuring and type safety - Other related cleanups for RubyMine inspections warnings --- .../create/devfile_fetcher.rb | 8 +- .../create/devfile_flattener.rb | 12 ++- .../create/main_component_updater.rb | 56 +++++++------- .../create/post_flatten_devfile_validator.rb | 77 ++++++++----------- .../create/pre_flatten_devfile_validator.rb | 4 +- .../project_cloner_component_inserter.rb | 40 +++++----- .../tools_injector_component_inserter.rb | 41 +++++----- .../create/volume_component_inserter.rb | 18 +++-- .../workspaces_dropdown_group_spec.rb | 4 +- .../remote_development/workspaces_spec.rb | 4 +- .../example.flattened-devfile.yaml | 3 + ...ributes-tools-injector-absent-devfile.yaml | 3 + ...butes-tools-injector-multiple-devfile.yaml | 3 + ...xample.invalid-component-missing-name.yaml | 3 + ...ttributes-container-overrides-devfile.yaml | 4 +- ...ents-attributes-pod-overrides-devfile.yaml | 4 +- ...nvalid-components-entry-empty-devfile.yaml | 3 + ...alid-components-entry-missing-devfile.yaml | 3 + .../example.invalid-extra-field-devfile.yaml | 3 + ...nvalid-invalid-schema-version-devfile.yaml | 3 + ...example.invalid-multi-command-devfile.yaml | 2 + ...ample.invalid-multi-component-devfile.yaml | 3 + ...xample.invalid-multi-endpoint-devfile.yaml | 3 + .../example.invalid-multi-event-devfile.yaml | 1 + ...xample.invalid-multi-variable-devfile.yaml | 2 + ...-command-apply-component-name-devfile.yaml | 2 + ...x-command-exec-component-name-devfile.yaml | 2 + ...estricted-prefix-command-name-devfile.yaml | 2 + ...onent-container-endpoint-name-devfile.yaml | 3 + ...tricted-prefix-component-name-devfile.yaml | 3 + ...efix-event-type-prestart-name-devfile.yaml | 1 + ...refix-event-type-prestop-name-devfile.yaml | 1 + ...stricted-prefix-variable-name-devfile.yaml | 2 + ...variable-name-with-underscore-devfile.yaml | 2 + ...root-attributes-pod-overrides-devfile.yaml | 4 +- ...onent-container-dedicated-pod-devfile.yaml | 3 + ...upported-component-type-image-devfile.yaml | 3 + ...ted-component-type-kubernetes-devfile.yaml | 3 + ...rted-component-type-openshift-devfile.yaml | 3 + ...upported-event-type-poststart-devfile.yaml | 1 + ...supported-event-type-poststop-devfile.yaml | 1 + ...nsupported-event-type-prestop-devfile.yaml | 1 + ...nsupported-parent-inheritance-devfile.yaml | 3 + ....invalid-unsupported-projects-devfile.yaml | 3 + ...id-unsupported-schema-version-devfile.yaml | 3 + ...-unsupported-starter-projects-devfile.yaml | 3 + ...xample.main-container-updated-devfile.yaml | 7 +- ...-updated-marketplace-disabled-devfile.yaml | 7 +- .../example.multi-entry-devfile.yaml | 2 + ....yaml => example.no-elements-devfile.yaml} | 0 ...xample.no-elements-flattened-devfile.yaml} | 3 + .../example.processed-devfile-v2.yaml | 1 + .../example.processed-devfile.yaml | 1 + ...ample.project-cloner-inserted-devfile.yaml | 1 + ...ample.tools-injector-inserted-devfile.yaml | 1 + .../create/devfile_fetcher_spec.rb | 4 +- .../create/devfile_flattener_spec.rb | 16 ++-- .../create/main_component_updater_spec.rb | 8 +- .../create/main_integration_spec.rb | 15 ++-- .../post_flatten_devfile_validator_spec.rb | 2 +- .../pre_flatten_devfile_validator_spec.rb | 6 +- .../project_cloner_component_inserter_spec.rb | 10 ++- .../tools_injector_component_inserter_spec.rb | 9 +-- .../create/volume_component_inserter_spec.rb | 10 ++- .../create/workspace_creator_spec.rb | 5 +- .../input/actual_state_calculator_spec.rb | 68 ++++++++-------- .../reconcile/main_integration_spec.rb | 4 +- .../desired_config_generator_v2_spec.rb | 2 +- .../reconcile/output/devfile_parser_spec.rb | 18 +++-- .../output/devfile_parser_v2_spec.rb | 6 +- .../output/response_payload_builder_spec.rb | 4 +- .../remote_development/integration_spec.rb | 10 +-- .../remote_development_shared_contexts.rb | 28 +++++-- 73 files changed, 360 insertions(+), 244 deletions(-) rename ee/spec/fixtures/remote_development/{example.no-components-devfile.yaml => example.no-elements-devfile.yaml} (100%) rename ee/spec/fixtures/remote_development/{example.no-components-flattened-devfile.yaml => example.no-elements-flattened-devfile.yaml} (58%) diff --git a/ee/lib/remote_development/workspace_operations/create/devfile_fetcher.rb b/ee/lib/remote_development/workspace_operations/create/devfile_fetcher.rb index 2ea187f4a02ac3..113043a7349ab8 100644 --- a/ee/lib/remote_development/workspace_operations/create/devfile_fetcher.rb +++ b/ee/lib/remote_development/workspace_operations/create/devfile_fetcher.rb @@ -45,8 +45,10 @@ def self.fetch(context) end begin - # convert YAML to JSON to remove YAML vulnerabilities - devfile = YAML.safe_load(YAML.safe_load(devfile_yaml).to_json) + # load YAML, convert YAML to JSON and load it again to remove YAML vulnerabilities + devfile_stringified = YAML.safe_load(YAML.safe_load(devfile_yaml).to_json) + # symbolize keys for domain logic processing of devfile (to_h is to avoid nil dereference error in RubyMine) + devfile = devfile_stringified.to_h.deep_symbolize_keys rescue RuntimeError, JSON::GeneratorError => e return Gitlab::Fp::Result.err(WorkspaceCreateDevfileYamlParseFailed.new( details: "Devfile YAML could not be parsed: #{e.message}" @@ -55,7 +57,7 @@ def self.fetch(context) Gitlab::Fp::Result.ok(context.merge({ # NOTE: The devfile_yaml should only be used for storing it in the database and not in any other - # subsequent step in the chain. + # later step in the chain. devfile_yaml: devfile_yaml, devfile: devfile })) diff --git a/ee/lib/remote_development/workspace_operations/create/devfile_flattener.rb b/ee/lib/remote_development/workspace_operations/create/devfile_flattener.rb index da98b1c847e3bb..31bb7c6917e373 100644 --- a/ee/lib/remote_development/workspace_operations/create/devfile_flattener.rb +++ b/ee/lib/remote_development/workspace_operations/create/devfile_flattener.rb @@ -12,7 +12,7 @@ def self.flatten(context) context => { devfile: Hash => devfile } begin - flattened_devfile_yaml = Devfile::Parser.flatten(YAML.dump(devfile)) + flattened_devfile_yaml = Devfile::Parser.flatten(YAML.dump(devfile.deep_stringify_keys)) rescue Devfile::CliError => e return Gitlab::Fp::Result.err(WorkspaceCreateDevfileFlattenFailed.new(details: e.message)) end @@ -21,9 +21,15 @@ def self.flatten(context) # Devfile::Parser gem will not produce invalid YAML. We own the gem, and will fix and add any regression # tests in the gem itself. No need to make this domain code more complex, more coupled, and less # cohesive by unnecessarily adding defensive coding against other code we also own. - processed_devfile = YAML.safe_load(flattened_devfile_yaml) + processed_devfile_stringified = YAML.safe_load(flattened_devfile_yaml) - processed_devfile['components'] ||= [] + # symbolize keys for domain logic processing of devfile (to_h is to avoid nil dereference error in RubyMine) + processed_devfile = processed_devfile_stringified.to_h.deep_symbolize_keys + + processed_devfile[:components] ||= [] + processed_devfile[:commands] ||= [] + processed_devfile[:events] ||= {} + processed_devfile[:variables] ||= {} Gitlab::Fp::Result.ok(context.merge(processed_devfile: processed_devfile)) end diff --git a/ee/lib/remote_development/workspace_operations/create/main_component_updater.rb b/ee/lib/remote_development/workspace_operations/create/main_component_updater.rb index 11635154750b08..91a3ce50926ee1 100644 --- a/ee/lib/remote_development/workspace_operations/create/main_component_updater.rb +++ b/ee/lib/remote_development/workspace_operations/create/main_component_updater.rb @@ -23,7 +23,7 @@ def self.update(context) # NOTE: We will always have exactly one main_component found, because we have already # validated this in post_flatten_devfile_validator.rb - main_component = processed_devfile['components'].find { |c| c.dig('attributes', 'gl/inject-editor') } + main_component = processed_devfile[:components].find { |c| c.dig(:attributes, :'gl/inject-editor') } update_main_container( main_component: main_component, @@ -56,46 +56,48 @@ def self.update_main_container(main_component:, tools_dir:, editor_port:, ssh_po fi ${GL_TOOLS_DIR}/init_tools.sh SH - main_component['container']['command'] = %w[/bin/sh -c] - main_component['container']['args'] = [container_args] - main_component['container']['env'] = [] if main_component['container']['env'].nil? - main_component['container']['env'] += [ + + container = main_component.fetch(:container) + + container[:command] = %w[/bin/sh -c] + container[:args] = [container_args] + + (container[:env] ||= []).append( { - 'name' => 'GL_TOOLS_DIR', - 'value' => tools_dir + name: "GL_TOOLS_DIR", + value: tools_dir }, { - 'name' => 'GL_EDITOR_LOG_LEVEL', - 'value' => 'info' + name: "GL_EDITOR_LOG_LEVEL", + value: "info" }, { - 'name' => 'GL_EDITOR_PORT', - 'value' => editor_port.to_s + name: "GL_EDITOR_PORT", + value: editor_port.to_s }, { - 'name' => 'GL_SSH_PORT', - 'value' => ssh_port.to_s + name: "GL_SSH_PORT", + value: ssh_port.to_s }, { - 'name' => 'GL_EDITOR_ENABLE_MARKETPLACE', - 'value' => enable_marketplace.to_s + name: "GL_EDITOR_ENABLE_MARKETPLACE", + value: enable_marketplace.to_s } - ] + ) - main_component['container']['endpoints'] = [] if main_component['container']['endpoints'].nil? - main_component['container']['endpoints'].append( + (container[:endpoints] ||= []).append( { - 'name' => 'editor-server', - 'targetPort' => editor_port, - 'exposure' => 'public', - 'secure' => true, - 'protocol' => 'https' + name: "editor-server", + targetPort: editor_port, + exposure: "public", + secure: true, + protocol: "https" }, { - 'name' => 'ssh-server', - 'targetPort' => ssh_port, - 'exposure' => 'internal', - 'secure' => true + name: "ssh-server", + targetPort: ssh_port, + exposure: "internal", + secure: true } ) end diff --git a/ee/lib/remote_development/workspace_operations/create/post_flatten_devfile_validator.rb b/ee/lib/remote_development/workspace_operations/create/post_flatten_devfile_validator.rb index 4e3c479e2fd856..e823fbfef51a69 100644 --- a/ee/lib/remote_development/workspace_operations/create/post_flatten_devfile_validator.rb +++ b/ee/lib/remote_development/workspace_operations/create/post_flatten_devfile_validator.rb @@ -12,17 +12,17 @@ class PostFlattenDevfileValidator # Devfile standard only allows name/id to be of the format /'^[a-z0-9]([-a-z0-9]*[a-z0-9])?$'/ # Hence, we do no need to restrict the prefix `gl_`. # However, we do that for the 'variables' in the processed_devfile since they do not have any such restriction - RESTRICTED_PREFIX = 'gl-' + RESTRICTED_PREFIX = "gl-" # Currently, we only support 'container' and 'volume' type components. # For container components, ensure no endpoint name starts with restricted_prefix - UNSUPPORTED_COMPONENT_TYPES = %w[kubernetes openshift image].freeze + UNSUPPORTED_COMPONENT_TYPES = %i[kubernetes openshift image].freeze # Currently, we only support 'exec' and 'apply' for validation - SUPPORTED_COMMAND_TYPES = %w[exec apply].freeze + SUPPORTED_COMMAND_TYPES = %i[exec apply].freeze # Currently, we only support `preStart` events - SUPPORTED_EVENTS = %w[preStart].freeze + SUPPORTED_EVENTS = %i[preStart].freeze # @param [Hash] context # @return [Gitlab::Fp::Result] @@ -43,8 +43,8 @@ def self.validate(context) def self.validate_projects(context) context => { processed_devfile: Hash => processed_devfile } - return err(_("'starterProjects' is not yet supported")) if processed_devfile['starterProjects'] - return err(_("'projects' is not yet supported")) if processed_devfile['projects'] + return err(_("'starterProjects' is not yet supported")) if processed_devfile[:starterProjects] + return err(_("'projects' is not yet supported")) if processed_devfile[:projects] Gitlab::Fp::Result.ok(context) end @@ -54,8 +54,8 @@ def self.validate_projects(context) def self.validate_root_attributes(context) context => { processed_devfile: Hash => processed_devfile } - return err(_("Attribute 'pod-overrides' is not yet supported")) if processed_devfile.dig('attributes', - 'pod-overrides') + return err(_("Attribute 'pod-overrides' is not yet supported")) if processed_devfile.dig(:attributes, + :"pod-overrides") Gitlab::Fp::Result.ok(context) end @@ -65,12 +65,12 @@ def self.validate_root_attributes(context) def self.validate_components(context) context => { processed_devfile: Hash => processed_devfile } - components = processed_devfile['components'] + components = processed_devfile[:components] - return err(_('No components present in devfile')) if components.blank? + return err(_("No components present in devfile")) if components.blank? injected_main_components = components.select do |component| - component.dig('attributes', 'gl/inject-editor') + component.dig(:attributes, :"gl/inject-editor") end return err(_("No component has 'gl/inject-editor' attribute")) if injected_main_components.empty? @@ -79,16 +79,16 @@ def self.validate_components(context) return err( format( _("Multiple components '%{name}' have 'gl/inject-editor' attribute"), - name: injected_main_components.pluck('name') # rubocop:disable CodeReuse/ActiveRecord -- this pluck isn't from ActiveRecord, it's from ActiveSupport + name: injected_main_components.pluck(:name) # rubocop:disable CodeReuse/ActiveRecord -- this pluck isn't from ActiveRecord, it's from ActiveSupport ) ) end - components_all_have_names = components.all? { |component| component['name'].present? } + components_all_have_names = components.all? { |component| component[:name].present? } return err(_("Components must have a 'name'")) unless components_all_have_names components.each do |component| - component_name = component.fetch('name') + component_name = component.fetch(:name) # Ensure no component name starts with restricted_prefix if component_name.downcase.start_with?(RESTRICTED_PREFIX) return err(format( @@ -105,10 +105,10 @@ def self.validate_components(context) end return err(_("Attribute 'container-overrides' is not yet supported")) if component.dig( - 'attributes', 'container-overrides') + :attributes, :"container-overrides") - return err(_("Attribute 'pod-overrides' is not yet supported")) if component.dig('attributes', - 'pod-overrides') + return err(_("Attribute 'pod-overrides' is not yet supported")) if component.dig(:attributes, + :"pod-overrides") end Gitlab::Fp::Result.ok(context) @@ -119,17 +119,17 @@ def self.validate_components(context) def self.validate_containers(context) context => { processed_devfile: Hash => processed_devfile } - components = processed_devfile['components'] + components = processed_devfile.fetch(:components) components.each do |component| - container = component['container'] + container = component[:container] next unless container - if container['dedicatedPod'] + if container[:dedicatedPod] return err( format( _("Property 'dedicatedPod' of component '%{name}' is not yet supported"), - name: component.fetch('name') + name: component.fetch(:name) ) ) end @@ -143,23 +143,23 @@ def self.validate_containers(context) def self.validate_endpoints(context) context => { processed_devfile: Hash => processed_devfile } - components = processed_devfile['components'] + components = processed_devfile.fetch(:components) err_result = nil components.each do |component| - container = component['container'] - next unless component.dig('container', 'endpoints') + container = component[:container] + next unless component.dig(:container, :endpoints) - container.fetch('endpoints').each do |endpoint| - endpoint_name = endpoint['name'] + container.fetch(:endpoints).each do |endpoint| + endpoint_name = endpoint.fetch(:name) next unless endpoint_name.downcase.start_with?(RESTRICTED_PREFIX) err_result = err( format( _("Endpoint name '%{endpoint}' of component '%{component}' must not start with '%{prefix}'"), endpoint: endpoint_name, - component: component.fetch('name'), + component: component.fetch(:name), prefix: RESTRICTED_PREFIX ) ) @@ -176,12 +176,9 @@ def self.validate_endpoints(context) def self.validate_commands(context) context => { processed_devfile: Hash => processed_devfile } - commands = processed_devfile['commands'] - return Gitlab::Fp::Result.ok(context) if commands.nil? - # Ensure no command name starts with restricted_prefix - commands.each do |command| - command_id = command.fetch('id') + processed_devfile.fetch(:commands).each do |command| + command_id = command.fetch(:id) if command_id.downcase.start_with?(RESTRICTED_PREFIX) return err( format( @@ -195,9 +192,9 @@ def self.validate_commands(context) # Ensure no command is referring to a component with restricted_prefix SUPPORTED_COMMAND_TYPES.each do |supported_command_type| command_type = command[supported_command_type] - next if command_type.nil? + next unless command_type - component_name = command_type['component'] + component_name = command_type[:component] next unless component_name.downcase.start_with?(RESTRICTED_PREFIX) return err( @@ -219,10 +216,7 @@ def self.validate_commands(context) def self.validate_events(context) context => { processed_devfile: Hash => processed_devfile } - events = processed_devfile['events'] - return Gitlab::Fp::Result.ok(context) if events.nil? - - events.each do |event_type, event_type_events| + processed_devfile.fetch(:events).each do |event_type, event_type_events| # Ensure no event type other than "preStart" are allowed unless SUPPORTED_EVENTS.include?(event_type) @@ -252,13 +246,10 @@ def self.validate_events(context) def self.validate_variables(context) context => { processed_devfile: Hash => processed_devfile } - variables = processed_devfile['variables'] - return Gitlab::Fp::Result.ok(context) if variables.nil? - restricted_prefix_underscore = RESTRICTED_PREFIX.tr("-", "_") - # Ensure no variables name starts with restricted_prefix - variables.each_key do |variable| + # Ensure no variable name starts with restricted_prefix + processed_devfile.fetch(:variables).each_key do |variable| [RESTRICTED_PREFIX, restricted_prefix_underscore].each do |prefix| next unless variable.downcase.start_with?(prefix) diff --git a/ee/lib/remote_development/workspace_operations/create/pre_flatten_devfile_validator.rb b/ee/lib/remote_development/workspace_operations/create/pre_flatten_devfile_validator.rb index 81294c15083ac0..29ed77b9f145f4 100644 --- a/ee/lib/remote_development/workspace_operations/create/pre_flatten_devfile_validator.rb +++ b/ee/lib/remote_development/workspace_operations/create/pre_flatten_devfile_validator.rb @@ -23,7 +23,7 @@ def self.validate_schema_version(context) context => { devfile: Hash => devfile } minimum_schema_version = Gem::Version.new(REQUIRED_DEVFILE_SCHEMA_VERSION) - devfile_schema_version_string = devfile.fetch('schemaVersion') + devfile_schema_version_string = devfile.fetch(:schemaVersion) begin devfile_schema_version = Gem::Version.new(devfile_schema_version_string) rescue ArgumentError @@ -50,7 +50,7 @@ def self.validate_schema_version(context) def self.validate_parent(context) context => { devfile: Hash => devfile } - return err(_("Inheriting from 'parent' is not yet supported")) if devfile['parent'] + return err(format(_("Inheriting from 'parent' is not yet supported"))) if devfile[:parent] Gitlab::Fp::Result.ok(context) end diff --git a/ee/lib/remote_development/workspace_operations/create/project_cloner_component_inserter.rb b/ee/lib/remote_development/workspace_operations/create/project_cloner_component_inserter.rb index e840e3c7da6d58..d8088778601ba4 100644 --- a/ee/lib/remote_development/workspace_operations/create/project_cloner_component_inserter.rb +++ b/ee/lib/remote_development/workspace_operations/create/project_cloner_component_inserter.rb @@ -70,43 +70,39 @@ def self.insert(context) # implement better error handling to allow cloner to be able to deal with different categories of errors # issue: https://gitlab.com/gitlab-org/gitlab/-/issues/408451 cloner_component = { - 'name' => 'gl-project-cloner', - 'container' => { - 'image' => image, - 'args' => [container_args], + name: "gl-project-cloner", + container: { + image: image, + args: [container_args], # command has been overridden here as the default command in the alpine/git # container invokes git directly - 'command' => %w[/bin/sh -c], - 'env' => [ + command: %w[/bin/sh -c], + env: [ { - 'name' => 'GL_PROJECT_CLONING_SUCCESSFUL_FILE', - 'value' => project_cloning_successful_file + name: "GL_PROJECT_CLONING_SUCCESSFUL_FILE", + value: project_cloning_successful_file } ], - 'memoryLimit' => '512Mi', - 'memoryRequest' => '256Mi', - 'cpuLimit' => '500m', - 'cpuRequest' => '100m' + memoryLimit: "512Mi", + memoryRequest: "256Mi", + cpuLimit: "500m", + cpuRequest: "100m" } } - processed_devfile['components'] ||= [] - processed_devfile['components'] << cloner_component + processed_devfile.fetch(:components) << cloner_component # create a command that will invoke the cloner cloner_command = { - 'id' => 'gl-project-cloner-command', - 'apply' => { - 'component' => cloner_component['name'] + id: "gl-project-cloner-command", + apply: { + component: cloner_component[:name] } } - processed_devfile['commands'] ||= [] - processed_devfile['commands'] << cloner_command + processed_devfile.fetch(:commands) << cloner_command # configure the workspace to run the cloner command upon workspace start - processed_devfile['events'] ||= {} - processed_devfile['events']['preStart'] ||= [] - processed_devfile['events']['preStart'] << cloner_command['id'] + processed_devfile.fetch(:events)[:preStart] << cloner_command[:id] context end diff --git a/ee/lib/remote_development/workspace_operations/create/tools_injector_component_inserter.rb b/ee/lib/remote_development/workspace_operations/create/tools_injector_component_inserter.rb index 4123e5436216e5..316651e4bb81ed 100644 --- a/ee/lib/remote_development/workspace_operations/create/tools_injector_component_inserter.rb +++ b/ee/lib/remote_development/workspace_operations/create/tools_injector_component_inserter.rb @@ -34,39 +34,34 @@ def self.insert(context) # @param [String] image # @return [void] def self.insert_tools_injector_component(processed_devfile:, tools_dir:, image:) - component_name = 'gl-tools-injector' + component_name = "gl-tools-injector" - tools_injector_component = { - 'name' => component_name, - 'container' => { - 'image' => image, - 'env' => [ + processed_devfile[:components] << { + name: component_name, + container: { + image: image, + env: [ { - 'name' => 'GL_TOOLS_DIR', - 'value' => tools_dir + name: "GL_TOOLS_DIR", + value: tools_dir } ], - 'memoryLimit' => '512Mi', - 'memoryRequest' => '256Mi', - 'cpuLimit' => '500m', - 'cpuRequest' => '100m' + memoryLimit: "512Mi", + memoryRequest: "256Mi", + cpuLimit: "500m", + cpuRequest: "100m" } } - processed_devfile['components'] << tools_injector_component - - processed_devfile['commands'] = [] if processed_devfile['commands'].nil? command_name = "#{component_name}-command" - processed_devfile['commands'] += [{ - 'id' => command_name, - 'apply' => { - 'component' => component_name + processed_devfile[:commands] << { + id: command_name, + apply: { + component: component_name } - }] + } - processed_devfile['events'] = {} if processed_devfile['events'].nil? - processed_devfile['events']['preStart'] = [] if processed_devfile['events']['preStart'].nil? - processed_devfile['events']['preStart'] += [command_name] + (processed_devfile.fetch(:events)[:preStart] ||= []) << command_name nil end diff --git a/ee/lib/remote_development/workspace_operations/create/volume_component_inserter.rb b/ee/lib/remote_development/workspace_operations/create/volume_component_inserter.rb index a317702c6b0548..be177c94ebfa7a 100644 --- a/ee/lib/remote_development/workspace_operations/create/volume_component_inserter.rb +++ b/ee/lib/remote_development/workspace_operations/create/volume_component_inserter.rb @@ -17,18 +17,20 @@ def self.insert(context) } volume_component = { - 'name' => volume_name, - 'volume' => { - 'size' => '50Gi' + name: volume_name, + volume: { + size: '50Gi' } } - processed_devfile['components'] << volume_component - processed_devfile['components'].each do |component| - next if component['container'].nil? + components = processed_devfile[:components] - component['container']['volumeMounts'] = [] if component['container']['volumeMounts'].nil? - component['container']['volumeMounts'] += [{ 'name' => volume_name, 'path' => volume_path }] + components << volume_component + components.each do |component| + next unless component[:container] + + volume_mount = { name: volume_name, path: volume_path } + (component.fetch(:container)[:volumeMounts] ||= []) << volume_mount end context diff --git a/ee/spec/features/remote_development/workspaces_dropdown_group_spec.rb b/ee/spec/features/remote_development/workspaces_dropdown_group_spec.rb index 712366526ae60e..bdf309a480dd79 100644 --- a/ee/spec/features/remote_development/workspaces_dropdown_group_spec.rb +++ b/ee/spec/features/remote_development/workspaces_dropdown_group_spec.rb @@ -12,7 +12,7 @@ let_it_be(:devfile_path) { '.devfile.yaml' } let_it_be(:project) do - files = { devfile_path => example_devfile } + files = { devfile_path => example_devfile_yaml } create(:project, :public, :in_group, :custom_repo, path: 'test-project', files: files, namespace: group) end @@ -96,7 +96,7 @@ click_button('Actions') - # Asserts that all workspaces actions are visible + # Asserts that all workspace actions are visible expect(page).to have_button('Stop') expect(page).to have_button('Terminate') diff --git a/ee/spec/features/remote_development/workspaces_spec.rb b/ee/spec/features/remote_development/workspaces_spec.rb index 36a2e83a6d4502..2786861a8bcd54 100644 --- a/ee/spec/features/remote_development/workspaces_spec.rb +++ b/ee/spec/features/remote_development/workspaces_spec.rb @@ -16,7 +16,7 @@ let_it_be(:devfile_path) { '.devfile.yaml' } let_it_be(:project) do - files = { devfile_path => example_devfile } + files = { devfile_path => example_devfile_yaml } create(:project, :public, :in_group, :custom_repo, path: 'test-project', files: files, namespace: group) end @@ -123,7 +123,7 @@ def do_reconcile_post(params:, agent_token:) wait_for_requests # noinspection RubyMismatchedArgumentType -- Rubymine is finding the wrong `select` select agent.name, from: 'Cluster agent' - # this field should be auto-fill when selecting agent + # this field should be autofilled when selecting agent click_button 'Add variable' fill_in 'Variable Key', with: variable_key fill_in 'Variable Value', with: variable_value diff --git a/ee/spec/fixtures/remote_development/example.flattened-devfile.yaml b/ee/spec/fixtures/remote_development/example.flattened-devfile.yaml index 397a5b7e9be0bd..10b57c73160b50 100644 --- a/ee/spec/fixtures/remote_development/example.flattened-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.flattened-devfile.yaml @@ -17,3 +17,6 @@ components: env: - name: MYSQL_ROOT_PASSWORD value: "my-secret-pw" +commands: [] +events: {} +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.invalid-attributes-tools-injector-absent-devfile.yaml b/ee/spec/fixtures/remote_development/example.invalid-attributes-tools-injector-absent-devfile.yaml index 3b26e99b120193..dfe0aeba8fff8e 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-attributes-tools-injector-absent-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-attributes-tools-injector-absent-devfile.yaml @@ -4,3 +4,6 @@ components: - name: tooling-container container: image: quay.io/mloriedo/universal-developer-image:ubi8-dw-demo +commands: [] +events: {} +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.invalid-attributes-tools-injector-multiple-devfile.yaml b/ee/spec/fixtures/remote_development/example.invalid-attributes-tools-injector-multiple-devfile.yaml index 555f6714c3944a..0c4641368feab8 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-attributes-tools-injector-multiple-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-attributes-tools-injector-multiple-devfile.yaml @@ -11,3 +11,6 @@ components: gl/inject-editor: true container: image: quay.io/mloriedo/universal-developer-image:ubi8-dw-demo +commands: [] +events: {} +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.invalid-component-missing-name.yaml b/ee/spec/fixtures/remote_development/example.invalid-component-missing-name.yaml index bb29c13f779404..5a67a566aba661 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-component-missing-name.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-component-missing-name.yaml @@ -6,3 +6,6 @@ components: gl/inject-editor: true container: image: quay.io/mloriedo/universal-developer-image:ubi8-dw-demo +commands: [] +events: {} +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.invalid-components-attributes-container-overrides-devfile.yaml b/ee/spec/fixtures/remote_development/example.invalid-components-attributes-container-overrides-devfile.yaml index a62fa0bcf93cac..171fe31d0362ae 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-components-attributes-container-overrides-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-components-attributes-container-overrides-devfile.yaml @@ -10,4 +10,6 @@ components: runAsGroup: 1001 container: image: quay.io/mloriedo/universal-developer-image:ubi8-dw-demo - +commands: [] +events: {} +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.invalid-components-attributes-pod-overrides-devfile.yaml b/ee/spec/fixtures/remote_development/example.invalid-components-attributes-pod-overrides-devfile.yaml index ba7c13741aa53e..11102c75f47128 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-components-attributes-pod-overrides-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-components-attributes-pod-overrides-devfile.yaml @@ -9,4 +9,6 @@ components: serviceAccountName: new-service-account container: image: quay.io/mloriedo/universal-developer-image:ubi8-dw-demo - +commands: [] +events: {} +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.invalid-components-entry-empty-devfile.yaml b/ee/spec/fixtures/remote_development/example.invalid-components-entry-empty-devfile.yaml index f103cb4a2e141b..c1f30f593161c3 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-components-entry-empty-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-components-entry-empty-devfile.yaml @@ -1,3 +1,6 @@ --- schemaVersion: 2.2.0 components: [] +commands: [] +events: {} +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.invalid-components-entry-missing-devfile.yaml b/ee/spec/fixtures/remote_development/example.invalid-components-entry-missing-devfile.yaml index 06ae3366eee5ab..86444be1ddfb21 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-components-entry-missing-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-components-entry-missing-devfile.yaml @@ -1,2 +1,5 @@ --- schemaVersion: 2.2.0 +commands: [] +events: {} +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.invalid-extra-field-devfile.yaml b/ee/spec/fixtures/remote_development/example.invalid-extra-field-devfile.yaml index a352ee627d86b1..9014a850c9d423 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-extra-field-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-extra-field-devfile.yaml @@ -12,3 +12,6 @@ components: image: quay.io/devfile/golang:latest memoryLimit: 1024Mi mountSources: true +commands: [] +events: {} +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.invalid-invalid-schema-version-devfile.yaml b/ee/spec/fixtures/remote_development/example.invalid-invalid-schema-version-devfile.yaml index de7515a4ad3d35..7f826ecfdb50d1 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-invalid-schema-version-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-invalid-schema-version-devfile.yaml @@ -6,3 +6,6 @@ components: gl/inject-editor: true container: image: quay.io/mloriedo/universal-developer-image:ubi8-dw-demo +commands: [] +events: {} +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.invalid-multi-command-devfile.yaml b/ee/spec/fixtures/remote_development/example.invalid-multi-command-devfile.yaml index a60b3aeaebc8a4..e4edf378144327 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-multi-command-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-multi-command-devfile.yaml @@ -14,3 +14,5 @@ commands: - id: example-invalid-second-component-command apply: component: gl-example-invalid-component +events: {} +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.invalid-multi-component-devfile.yaml b/ee/spec/fixtures/remote_development/example.invalid-multi-component-devfile.yaml index ed25b44f69adbf..9892bf07782f93 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-multi-component-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-multi-component-devfile.yaml @@ -10,3 +10,6 @@ components: gl/inject-editor: true container: image: quay.io/mloriedo/universal-developer-image:ubi8-dw-demo +commands: [] +events: {} +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.invalid-multi-endpoint-devfile.yaml b/ee/spec/fixtures/remote_development/example.invalid-multi-endpoint-devfile.yaml index dfa607354e945c..d8a20fde5c2d00 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-multi-endpoint-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-multi-endpoint-devfile.yaml @@ -19,3 +19,6 @@ components: targetPort: 3102 protocol: https exposure: none +commands: [] +events: {} +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.invalid-multi-event-devfile.yaml b/ee/spec/fixtures/remote_development/example.invalid-multi-event-devfile.yaml index c14d47f6fa9b0c..fb647f7615aedf 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-multi-event-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-multi-event-devfile.yaml @@ -15,3 +15,4 @@ events: preStart: - example - gl-example +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.invalid-multi-variable-devfile.yaml b/ee/spec/fixtures/remote_development/example.invalid-multi-variable-devfile.yaml index 7b5a28d8a8b58e..fe35c86e39be50 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-multi-variable-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-multi-variable-devfile.yaml @@ -6,6 +6,8 @@ components: gl/inject-editor: true container: image: quay.io/mloriedo/universal-developer-image:ubi8-dw-demo +commands: [] +events: {} # This example proves that all variables are processed, not just the first one variables: example: "valid" diff --git a/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-command-apply-component-name-devfile.yaml b/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-command-apply-component-name-devfile.yaml index c0cc9298ca12f1..3fe9a2b291a4c4 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-command-apply-component-name-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-command-apply-component-name-devfile.yaml @@ -10,3 +10,5 @@ commands: - id: example apply: component: gl-example +events: {} +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-command-exec-component-name-devfile.yaml b/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-command-exec-component-name-devfile.yaml index ab31818fd9ed59..eb67d6ca6a35c3 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-command-exec-component-name-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-command-exec-component-name-devfile.yaml @@ -12,3 +12,5 @@ commands: component: gl-example commandLine: mvn clean workingDir: /projects/spring-petclinic +events: {} +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-command-name-devfile.yaml b/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-command-name-devfile.yaml index e646c33691f493..6db207f3f7bfe5 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-command-name-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-command-name-devfile.yaml @@ -12,3 +12,5 @@ commands: component: example commandLine: mvn clean workingDir: /projects/spring-petclinic +events: {} +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-component-container-endpoint-name-devfile.yaml b/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-component-container-endpoint-name-devfile.yaml index c6d2811ffc16bf..8fc7971a9a38d9 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-component-container-endpoint-name-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-component-container-endpoint-name-devfile.yaml @@ -11,3 +11,6 @@ components: targetPort: 3101 protocol: https exposure: none +commands: [] +events: {} +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-component-name-devfile.yaml b/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-component-name-devfile.yaml index 15d6d5777fa3b8..082121a6f13b9d 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-component-name-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-component-name-devfile.yaml @@ -6,3 +6,6 @@ components: gl/inject-editor: true container: image: quay.io/mloriedo/universal-developer-image:ubi8-dw-demo +commands: [] +events: {} +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-event-type-prestart-name-devfile.yaml b/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-event-type-prestart-name-devfile.yaml index 8f16fe96aff6b1..0dfb59ba764680 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-event-type-prestart-name-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-event-type-prestart-name-devfile.yaml @@ -14,3 +14,4 @@ events: preStart: - example - gl-example +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-event-type-prestop-name-devfile.yaml b/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-event-type-prestop-name-devfile.yaml index 218a480a3b583d..beb62f964e72a9 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-event-type-prestop-name-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-event-type-prestop-name-devfile.yaml @@ -16,3 +16,4 @@ events: preStop: - example - gl-example +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-variable-name-devfile.yaml b/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-variable-name-devfile.yaml index 0d28d092f76409..f9c28ee10014ed 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-variable-name-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-variable-name-devfile.yaml @@ -6,5 +6,7 @@ components: gl/inject-editor: true container: image: quay.io/mloriedo/universal-developer-image:ubi8-dw-demo +commands: [] +events: {} variables: gl-example: "abc" diff --git a/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-variable-name-with-underscore-devfile.yaml b/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-variable-name-with-underscore-devfile.yaml index 0b9e88a68fbd0e..66da33fc87139d 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-variable-name-with-underscore-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-restricted-prefix-variable-name-with-underscore-devfile.yaml @@ -6,5 +6,7 @@ components: gl/inject-editor: true container: image: quay.io/mloriedo/universal-developer-image:ubi8-dw-demo +commands: [] +events: {} variables: gl_example: "abc" diff --git a/ee/spec/fixtures/remote_development/example.invalid-root-attributes-pod-overrides-devfile.yaml b/ee/spec/fixtures/remote_development/example.invalid-root-attributes-pod-overrides-devfile.yaml index 80cd09b6a57a9a..7492c4226dfdeb 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-root-attributes-pod-overrides-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-root-attributes-pod-overrides-devfile.yaml @@ -10,4 +10,6 @@ components: gl/inject-editor: true container: image: quay.io/mloriedo/universal-developer-image:ubi8-dw-demo - +commands: [] +events: {} +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.invalid-unsupported-component-container-dedicated-pod-devfile.yaml b/ee/spec/fixtures/remote_development/example.invalid-unsupported-component-container-dedicated-pod-devfile.yaml index 5d1bac0741bed8..627ad2aec81e14 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-unsupported-component-container-dedicated-pod-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-unsupported-component-container-dedicated-pod-devfile.yaml @@ -7,3 +7,6 @@ components: container: image: quay.io/mloriedo/universal-developer-image:ubi8-dw-demo dedicatedPod: true +commands: [] +events: {} +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.invalid-unsupported-component-type-image-devfile.yaml b/ee/spec/fixtures/remote_development/example.invalid-unsupported-component-type-image-devfile.yaml index 63d39dbb0f6ce1..13daf14c7d2dd9 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-unsupported-component-type-image-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-unsupported-component-type-image-devfile.yaml @@ -13,3 +13,6 @@ components: - 'MY_ENV=/home/path' buildContext: . rootRequired: false +commands: [] +events: {} +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.invalid-unsupported-component-type-kubernetes-devfile.yaml b/ee/spec/fixtures/remote_development/example.invalid-unsupported-component-type-kubernetes-devfile.yaml index ff729b338db0f9..f109b3a207dcc2 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-unsupported-component-type-kubernetes-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-unsupported-component-type-kubernetes-devfile.yaml @@ -18,3 +18,6 @@ components: image: myimage command: ["some", "command"] restartPolicy: Never +commands: [] +events: {} +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.invalid-unsupported-component-type-openshift-devfile.yaml b/ee/spec/fixtures/remote_development/example.invalid-unsupported-component-type-openshift-devfile.yaml index a0f7812e980585..838b55fc5520c7 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-unsupported-component-type-openshift-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-unsupported-component-type-openshift-devfile.yaml @@ -18,3 +18,6 @@ components: image: myimage command: ["some", "command"] restartPolicy: Never +commands: [] +events: {} +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.invalid-unsupported-event-type-poststart-devfile.yaml b/ee/spec/fixtures/remote_development/example.invalid-unsupported-event-type-poststart-devfile.yaml index 6381db0e4672b2..49133608fe5134 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-unsupported-event-type-poststart-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-unsupported-event-type-poststart-devfile.yaml @@ -15,3 +15,4 @@ commands: events: postStart: - example +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.invalid-unsupported-event-type-poststop-devfile.yaml b/ee/spec/fixtures/remote_development/example.invalid-unsupported-event-type-poststop-devfile.yaml index 36ae8df0172cb2..bdb08e2240a712 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-unsupported-event-type-poststop-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-unsupported-event-type-poststop-devfile.yaml @@ -13,3 +13,4 @@ commands: events: postStop: - example +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.invalid-unsupported-event-type-prestop-devfile.yaml b/ee/spec/fixtures/remote_development/example.invalid-unsupported-event-type-prestop-devfile.yaml index acff86fa2fc2fc..63039bf768db94 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-unsupported-event-type-prestop-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-unsupported-event-type-prestop-devfile.yaml @@ -15,3 +15,4 @@ commands: events: preStop: - example +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.invalid-unsupported-parent-inheritance-devfile.yaml b/ee/spec/fixtures/remote_development/example.invalid-unsupported-parent-inheritance-devfile.yaml index ca1e7f122397bb..ab68435c2dee6e 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-unsupported-parent-inheritance-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-unsupported-parent-inheritance-devfile.yaml @@ -9,3 +9,6 @@ components: gl/inject-editor: true container: image: quay.io/mloriedo/universal-developer-image:ubi8-dw-demo +commands: [] +events: {} +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.invalid-unsupported-projects-devfile.yaml b/ee/spec/fixtures/remote_development/example.invalid-unsupported-projects-devfile.yaml index 18604623079218..8cd9e932ce440c 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-unsupported-projects-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-unsupported-projects-devfile.yaml @@ -15,3 +15,6 @@ components: gl/inject-editor: true container: image: quay.io/mloriedo/universal-developer-image:ubi8-dw-demo +commands: [] +events: {} +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.invalid-unsupported-schema-version-devfile.yaml b/ee/spec/fixtures/remote_development/example.invalid-unsupported-schema-version-devfile.yaml index 19af3be7d7dc74..39e6b3f60c595d 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-unsupported-schema-version-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-unsupported-schema-version-devfile.yaml @@ -6,3 +6,6 @@ components: gl/inject-editor: true container: image: quay.io/mloriedo/universal-developer-image:ubi8-dw-demo +commands: [] +events: {} +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.invalid-unsupported-starter-projects-devfile.yaml b/ee/spec/fixtures/remote_development/example.invalid-unsupported-starter-projects-devfile.yaml index 71a59e5057317f..9258b549d17e57 100644 --- a/ee/spec/fixtures/remote_development/example.invalid-unsupported-starter-projects-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.invalid-unsupported-starter-projects-devfile.yaml @@ -15,3 +15,6 @@ components: gl/inject-editor: true container: image: quay.io/mloriedo/universal-developer-image:ubi8-dw-demo +commands: [] +events: {} +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.main-container-updated-devfile.yaml b/ee/spec/fixtures/remote_development/example.main-container-updated-devfile.yaml index b5cc3ee036ba70..2f672cd95a1b70 100644 --- a/ee/spec/fixtures/remote_development/example.main-container-updated-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.main-container-updated-devfile.yaml @@ -61,10 +61,11 @@ components: memoryRequest: 256Mi cpuLimit: 500m cpuRequest: 100m -events: - preStart: - - gl-tools-injector-command commands: - id: gl-tools-injector-command apply: component: gl-tools-injector +events: + preStart: + - gl-tools-injector-command +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.main-container-updated-marketplace-disabled-devfile.yaml b/ee/spec/fixtures/remote_development/example.main-container-updated-marketplace-disabled-devfile.yaml index b5cc3ee036ba70..2f672cd95a1b70 100644 --- a/ee/spec/fixtures/remote_development/example.main-container-updated-marketplace-disabled-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.main-container-updated-marketplace-disabled-devfile.yaml @@ -61,10 +61,11 @@ components: memoryRequest: 256Mi cpuLimit: 500m cpuRequest: 100m -events: - preStart: - - gl-tools-injector-command commands: - id: gl-tools-injector-command apply: component: gl-tools-injector +events: + preStart: + - gl-tools-injector-command +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.multi-entry-devfile.yaml b/ee/spec/fixtures/remote_development/example.multi-entry-devfile.yaml index f58eca63b4ecb3..8a37e943a53aee 100644 --- a/ee/spec/fixtures/remote_development/example.multi-entry-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.multi-entry-devfile.yaml @@ -32,3 +32,5 @@ commands: - id: example-valid-second-command apply: component: example-valid-second-component +events: {} +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.no-components-devfile.yaml b/ee/spec/fixtures/remote_development/example.no-elements-devfile.yaml similarity index 100% rename from ee/spec/fixtures/remote_development/example.no-components-devfile.yaml rename to ee/spec/fixtures/remote_development/example.no-elements-devfile.yaml diff --git a/ee/spec/fixtures/remote_development/example.no-components-flattened-devfile.yaml b/ee/spec/fixtures/remote_development/example.no-elements-flattened-devfile.yaml similarity index 58% rename from ee/spec/fixtures/remote_development/example.no-components-flattened-devfile.yaml rename to ee/spec/fixtures/remote_development/example.no-elements-flattened-devfile.yaml index 1d778dc3d570e3..a1ca204355dfe7 100644 --- a/ee/spec/fixtures/remote_development/example.no-components-flattened-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.no-elements-flattened-devfile.yaml @@ -2,3 +2,6 @@ schemaVersion: 2.2.0 metadata: {} components: [] +commands: [] +events: {} +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.processed-devfile-v2.yaml b/ee/spec/fixtures/remote_development/example.processed-devfile-v2.yaml index 2566972d882eb5..88209bc96bbbf2 100644 --- a/ee/spec/fixtures/remote_development/example.processed-devfile-v2.yaml +++ b/ee/spec/fixtures/remote_development/example.processed-devfile-v2.yaml @@ -125,3 +125,4 @@ commands: - id: gl-project-cloner-command apply: component: gl-project-cloner +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.processed-devfile.yaml b/ee/spec/fixtures/remote_development/example.processed-devfile.yaml index 2566972d882eb5..88209bc96bbbf2 100644 --- a/ee/spec/fixtures/remote_development/example.processed-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.processed-devfile.yaml @@ -125,3 +125,4 @@ commands: - id: gl-project-cloner-command apply: component: gl-project-cloner +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.project-cloner-inserted-devfile.yaml b/ee/spec/fixtures/remote_development/example.project-cloner-inserted-devfile.yaml index 287ab95cd8b86a..5a9d529f5b3a08 100644 --- a/ee/spec/fixtures/remote_development/example.project-cloner-inserted-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.project-cloner-inserted-devfile.yaml @@ -110,3 +110,4 @@ commands: - id: gl-project-cloner-command apply: component: gl-project-cloner +variables: {} diff --git a/ee/spec/fixtures/remote_development/example.tools-injector-inserted-devfile.yaml b/ee/spec/fixtures/remote_development/example.tools-injector-inserted-devfile.yaml index 8b1dcc80e29f97..5901c3a39ff474 100644 --- a/ee/spec/fixtures/remote_development/example.tools-injector-inserted-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.tools-injector-inserted-devfile.yaml @@ -34,3 +34,4 @@ commands: - id: gl-tools-injector-command apply: component: gl-tools-injector +variables: {} diff --git a/ee/spec/lib/remote_development/workspace_operations/create/devfile_fetcher_spec.rb b/ee/spec/lib/remote_development/workspace_operations/create/devfile_fetcher_spec.rb index 63122076ca4710..dc4fc43559e425 100644 --- a/ee/spec/lib/remote_development/workspace_operations/create/devfile_fetcher_spec.rb +++ b/ee/spec/lib/remote_development/workspace_operations/create/devfile_fetcher_spec.rb @@ -18,7 +18,7 @@ let(:devfile_ref) { 'main' } let(:devfile_path) { '.devfile.yaml' } let(:devfile_fixture_name) { 'example.devfile.yaml' } - let(:devfile_yaml) { read_devfile(devfile_fixture_name) } + let(:devfile_yaml) { read_devfile_yaml(devfile_fixture_name) } let(:workspace_root) { '/projects' } let(:params) do { @@ -39,7 +39,7 @@ end context 'when params are valid' do - let(:devfile) { YAML.safe_load(devfile_yaml) } + let(:devfile) { yaml_safe_load_symbolized(devfile_yaml) } it 'returns an ok Result containing the original params and the devfile_yaml_string' do expect(result).to eq( diff --git a/ee/spec/lib/remote_development/workspace_operations/create/devfile_flattener_spec.rb b/ee/spec/lib/remote_development/workspace_operations/create/devfile_flattener_spec.rb index 81128dc0283770..dd9d9117a83ce1 100644 --- a/ee/spec/lib/remote_development/workspace_operations/create/devfile_flattener_spec.rb +++ b/ee/spec/lib/remote_development/workspace_operations/create/devfile_flattener_spec.rb @@ -5,9 +5,9 @@ RSpec.describe RemoteDevelopment::WorkspaceOperations::Create::DevfileFlattener, feature_category: :workspaces do include_context 'with remote development shared fixtures' - let(:devfile_yaml) { example_devfile } - let(:devfile) { YAML.safe_load(devfile_yaml) } - let(:expected_processed_devfile) { YAML.safe_load(example_flattened_devfile) } + let(:devfile_yaml) { example_devfile_yaml } + let(:devfile) { yaml_safe_load_symbolized(devfile_yaml) } + let(:expected_processed_devfile) { example_flattened_devfile } let(:context) { { devfile: devfile } } subject(:result) do @@ -25,13 +25,13 @@ ) end - context "when devfile has no components" do - let(:devfile_yaml) { read_devfile('example.no-components-devfile.yaml') } + context "when devfile has no elements" do + let(:devfile_yaml) { read_devfile_yaml('example.no-elements-devfile.yaml') } let(:expected_processed_devfile) do - YAML.safe_load(read_devfile('example.no-components-flattened-devfile.yaml')) + yaml_safe_load_symbolized(read_devfile_yaml("example.no-elements-flattened-devfile.yaml")) end - it "adds an empty components entry" do + it "adds empty elements" do expect(result).to eq( Gitlab::Fp::Result.ok( { @@ -44,7 +44,7 @@ end context "when flatten raises a Devfile::CliError" do - let(:devfile_yaml) { read_devfile('example.invalid-extra-field-devfile.yaml') } + let(:devfile_yaml) { read_devfile_yaml("example.invalid-extra-field-devfile.yaml") } it "returns the error message from the CLI" do expected_error_message = diff --git a/ee/spec/lib/remote_development/workspace_operations/create/main_component_updater_spec.rb b/ee/spec/lib/remote_development/workspace_operations/create/main_component_updater_spec.rb index 63d2ca6e7597bc..18813d77b30af4 100644 --- a/ee/spec/lib/remote_development/workspace_operations/create/main_component_updater_spec.rb +++ b/ee/spec/lib/remote_development/workspace_operations/create/main_component_updater_spec.rb @@ -5,10 +5,12 @@ RSpec.describe RemoteDevelopment::WorkspaceOperations::Create::MainComponentUpdater, feature_category: :workspaces do include_context 'with remote development shared fixtures' - let(:input_processed_devfile_name) { 'example.tools-injector-inserted-devfile.yaml' } - let(:input_processed_devfile) { YAML.safe_load(read_devfile(input_processed_devfile_name)).to_h } + let(:input_processed_devfile) do + yaml_safe_load_symbolized(read_devfile_yaml("example.tools-injector-inserted-devfile.yaml")) + end + let(:expected_processed_devfile_name) { 'example.main-container-updated-devfile.yaml' } - let(:expected_processed_devfile) { YAML.safe_load(read_devfile(expected_processed_devfile_name)).to_h } + let(:expected_processed_devfile) { yaml_safe_load_symbolized(read_devfile_yaml(expected_processed_devfile_name)) } let(:vscode_extensions_gallery_metadata_enabled) { false } diff --git a/ee/spec/lib/remote_development/workspace_operations/create/main_integration_spec.rb b/ee/spec/lib/remote_development/workspace_operations/create/main_integration_spec.rb index 022882e11c8da8..354375b17c3360 100644 --- a/ee/spec/lib/remote_development/workspace_operations/create/main_integration_spec.rb +++ b/ee/spec/lib/remote_development/workspace_operations/create/main_integration_spec.rb @@ -16,8 +16,8 @@ let(:devfile_ref) { 'master' } let(:devfile_path) { '.devfile.yaml' } let(:devfile_fixture_name) { 'example.devfile.yaml' } - let(:devfile_yaml) { read_devfile(devfile_fixture_name) } - let(:expected_processed_devfile) { YAML.safe_load(example_processed_devfile).to_h } + let(:devfile_yaml) { read_devfile_yaml(devfile_fixture_name) } + let(:expected_processed_devfile) { example_processed_devfile } let(:workspace_root) { '/projects' } let(:dns_zone) { 'dns.zone.me' } let(:variables) do @@ -127,7 +127,7 @@ # noinspection RubyResolve expect(workspace.devfile).to eq(devfile_yaml) - actual_processed_devfile = YAML.safe_load(workspace.processed_devfile).to_h + actual_processed_devfile = yaml_safe_load_symbolized(workspace.processed_devfile) expect(actual_processed_devfile).to eq(expected_processed_devfile) variables.each do |variable| @@ -216,10 +216,11 @@ it 'uses image override' do workspace = response.fetch(:payload).fetch(:workspace) - processed_devfile = YAML.safe_load(workspace.processed_devfile).to_h - image_from_processed_devfile = processed_devfile["components"] - &.find { |component| component['name'] == 'gl-tools-injector' } - &.dig('container', 'image') + processed_devfile = yaml_safe_load_symbolized(workspace.processed_devfile) + image_from_processed_devfile = + processed_devfile[:components] + .find { |component| component.fetch(:name) == "gl-tools-injector" } + .dig(:container, :image) expect(image_from_processed_devfile).to eq(tools_injector_image_from_settings) end end diff --git a/ee/spec/lib/remote_development/workspace_operations/create/post_flatten_devfile_validator_spec.rb b/ee/spec/lib/remote_development/workspace_operations/create/post_flatten_devfile_validator_spec.rb index 90a2d2adba6348..261146ab3d5502 100644 --- a/ee/spec/lib/remote_development/workspace_operations/create/post_flatten_devfile_validator_spec.rb +++ b/ee/spec/lib/remote_development/workspace_operations/create/post_flatten_devfile_validator_spec.rb @@ -8,7 +8,7 @@ include_context 'with remote development shared fixtures' let(:flattened_devfile_name) { 'example.flattened-with-entries-devfile.yaml' } - let(:processed_devfile) { YAML.safe_load(read_devfile(flattened_devfile_name)) } + let(:processed_devfile) { yaml_safe_load_symbolized(read_devfile_yaml(flattened_devfile_name)) } let(:context) { { processed_devfile: processed_devfile } } subject(:result) do diff --git a/ee/spec/lib/remote_development/workspace_operations/create/pre_flatten_devfile_validator_spec.rb b/ee/spec/lib/remote_development/workspace_operations/create/pre_flatten_devfile_validator_spec.rb index 7258d4f6b23588..7e576a3b7cf74d 100644 --- a/ee/spec/lib/remote_development/workspace_operations/create/pre_flatten_devfile_validator_spec.rb +++ b/ee/spec/lib/remote_development/workspace_operations/create/pre_flatten_devfile_validator_spec.rb @@ -1,14 +1,14 @@ # frozen_string_literal: true -require 'fast_spec_helper' +require "fast_spec_helper" RSpec.describe ::RemoteDevelopment::WorkspaceOperations::Create::PreFlattenDevfileValidator, feature_category: :workspaces do include ResultMatchers include_context 'with remote development shared fixtures' - let(:devfile_name) { 'example.devfile.yaml' } - let(:devfile) { YAML.safe_load(read_devfile(devfile_name)).to_h } + let(:devfile_name) { "example.devfile.yaml" } + let(:devfile) { yaml_safe_load_symbolized(read_devfile_yaml(devfile_name)) } let(:context) { { devfile: devfile } } subject(:result) do diff --git a/ee/spec/lib/remote_development/workspace_operations/create/project_cloner_component_inserter_spec.rb b/ee/spec/lib/remote_development/workspace_operations/create/project_cloner_component_inserter_spec.rb index 1f8b3861005d15..21d3aa0eef50f4 100644 --- a/ee/spec/lib/remote_development/workspace_operations/create/project_cloner_component_inserter_spec.rb +++ b/ee/spec/lib/remote_development/workspace_operations/create/project_cloner_component_inserter_spec.rb @@ -11,10 +11,12 @@ instance_double("Project", path: project_path, http_url_to_repo: http_url_to_repo) # rubocop:disable RSpec/VerifiedDoubleReference -- We're using the quoted version so we can use fast_spec_helper end - let(:input_processed_devfile_name) { 'example.main-container-updated-devfile.yaml' } - let(:input_processed_devfile) { YAML.safe_load(read_devfile(input_processed_devfile_name)).to_h } - let(:expected_processed_devfile_name) { 'example.project-cloner-inserted-devfile.yaml' } - let(:expected_processed_devfile) { YAML.safe_load(read_devfile(expected_processed_devfile_name)).to_h } + let(:input_processed_devfile) do + yaml_safe_load_symbolized(read_devfile_yaml("example.main-container-updated-devfile.yaml")) + end + + let(:expected_processed_devfile_name) { "example.project-cloner-inserted-devfile.yaml" } + let(:expected_processed_devfile) { yaml_safe_load_symbolized(read_devfile_yaml(expected_processed_devfile_name)) } let(:component_name) { "gl-project-cloner" } let(:context) do { diff --git a/ee/spec/lib/remote_development/workspace_operations/create/tools_injector_component_inserter_spec.rb b/ee/spec/lib/remote_development/workspace_operations/create/tools_injector_component_inserter_spec.rb index 13512974b94523..696b61a7ee31d7 100644 --- a/ee/spec/lib/remote_development/workspace_operations/create/tools_injector_component_inserter_spec.rb +++ b/ee/spec/lib/remote_development/workspace_operations/create/tools_injector_component_inserter_spec.rb @@ -5,10 +5,9 @@ RSpec.describe RemoteDevelopment::WorkspaceOperations::Create::ToolsInjectorComponentInserter, feature_category: :workspaces do include_context 'with remote development shared fixtures' - let(:input_processed_devfile_name) { 'example.flattened-devfile.yaml' } - let(:input_processed_devfile) { YAML.safe_load(read_devfile(input_processed_devfile_name)).to_h } - let(:expected_processed_devfile_name) { 'example.tools-injector-inserted-devfile.yaml' } - let(:expected_processed_devfile) { YAML.safe_load(read_devfile(expected_processed_devfile_name)).to_h } + let(:input_processed_devfile) { yaml_safe_load_symbolized(read_devfile_yaml("example.flattened-devfile.yaml")) } + let(:expected_processed_devfile_name) { "example.tools-injector-inserted-devfile.yaml" } + let(:expected_processed_devfile) { yaml_safe_load_symbolized(read_devfile_yaml(expected_processed_devfile_name)) } let(:tools_injector_image_from_settings) do "registry.gitlab.com/gitlab-org/remote-development/gitlab-workspaces-tools:2.0.0" end @@ -46,7 +45,7 @@ let(:tools_injector_image_from_settings) { 'my/awesome/image:42' } it 'uses image override' do - image_from_processed_devfile = returned_value[:processed_devfile]["components"][2]["container"]["image"] + image_from_processed_devfile = returned_value.dig(:processed_devfile, :components, 2, :container, :image) expect(image_from_processed_devfile).to eq(tools_injector_image_from_settings) end end diff --git a/ee/spec/lib/remote_development/workspace_operations/create/volume_component_inserter_spec.rb b/ee/spec/lib/remote_development/workspace_operations/create/volume_component_inserter_spec.rb index 8ce4736976265c..ddbcfc46b6a4c2 100644 --- a/ee/spec/lib/remote_development/workspace_operations/create/volume_component_inserter_spec.rb +++ b/ee/spec/lib/remote_development/workspace_operations/create/volume_component_inserter_spec.rb @@ -5,10 +5,12 @@ RSpec.describe RemoteDevelopment::WorkspaceOperations::Create::VolumeComponentInserter, feature_category: :workspaces do include_context 'with remote development shared fixtures' - let(:input_processed_devfile_name) { 'example.project-cloner-inserted-devfile.yaml' } - let(:input_processed_devfile) { YAML.safe_load(read_devfile(input_processed_devfile_name)).to_h } - let(:expected_processed_devfile_name) { 'example.processed-devfile.yaml' } - let(:expected_processed_devfile) { YAML.safe_load(read_devfile(expected_processed_devfile_name)).to_h } + let(:input_processed_devfile) do + yaml_safe_load_symbolized(read_devfile_yaml("example.project-cloner-inserted-devfile.yaml")) + end + + let(:expected_processed_devfile_name) { "example.processed-devfile.yaml" } + let(:expected_processed_devfile) { yaml_safe_load_symbolized(read_devfile_yaml(expected_processed_devfile_name)) } let(:component_name) { "gl-workspace-data" } let(:volume_name) { "gl-workspace-data" } let(:context) do diff --git a/ee/spec/lib/remote_development/workspace_operations/create/workspace_creator_spec.rb b/ee/spec/lib/remote_development/workspace_operations/create/workspace_creator_spec.rb index 21488a0cd5dfbe..6ae4e4c7773b9e 100644 --- a/ee/spec/lib/remote_development/workspace_operations/create/workspace_creator_spec.rb +++ b/ee/spec/lib/remote_development/workspace_operations/create/workspace_creator_spec.rb @@ -13,10 +13,9 @@ let_it_be(:personal_access_token) { create(:personal_access_token, user: user) } let(:random_string) { 'abcdef' } let(:devfile_path) { '.devfile.yaml' } - let(:devfile_yaml) { example_devfile } - let(:processed_devfile) { YAML.safe_load(example_flattened_devfile) } + let(:devfile_yaml) { example_devfile_yaml } + let(:processed_devfile) { example_flattened_devfile } let(:desired_state) { RemoteDevelopment::WorkspaceOperations::States::RUNNING } - let(:processed_devfile_yaml) { YAML.safe_load(example_processed_devfile) } let(:workspace_root) { '/projects' } let(:params) do diff --git a/ee/spec/lib/remote_development/workspace_operations/reconcile/input/actual_state_calculator_spec.rb b/ee/spec/lib/remote_development/workspace_operations/reconcile/input/actual_state_calculator_spec.rb index 6896ef211721f9..5a8c88d80f0153 100644 --- a/ee/spec/lib/remote_development/workspace_operations/reconcile/input/actual_state_calculator_spec.rb +++ b/ee/spec/lib/remote_development/workspace_operations/reconcile/input/actual_state_calculator_spec.rb @@ -92,7 +92,7 @@ context 'when new workspace has been created or existing workspace has been scaled up' do let(:expected_actual_state) { RemoteDevelopment::WorkspaceOperations::States::RUNNING } let(:latest_k8s_deployment_info) do - YAML.safe_load( + yaml_safe_load_symbolized( <<~WORKSPACE_STATUS_YAML spec: replicas: 1 @@ -104,7 +104,7 @@ - reason: NewReplicaSetAvailable type: Progressing WORKSPACE_STATUS_YAML - ).deep_symbolize_keys + ) end it 'returns the expected actual state' do @@ -116,7 +116,7 @@ context 'when existing workspace has been scaled down' do let(:expected_actual_state) { RemoteDevelopment::WorkspaceOperations::States::STOPPED } let(:latest_k8s_deployment_info) do - YAML.safe_load( + yaml_safe_load_symbolized( <<~WORKSPACE_STATUS_YAML spec: replicas: 0 @@ -127,7 +127,7 @@ - reason: NewReplicaSetAvailable type: Progressing WORKSPACE_STATUS_YAML - ).deep_symbolize_keys + ) end it 'returns the expected actual state' do @@ -139,7 +139,7 @@ context 'when status does not contain required information' do let(:expected_actual_state) { RemoteDevelopment::WorkspaceOperations::States::UNKNOWN } let(:latest_k8s_deployment_info) do - YAML.safe_load( + yaml_safe_load_symbolized( <<~WORKSPACE_STATUS_YAML spec: test: 0 @@ -150,7 +150,7 @@ - reason: NewReplicaSetAvailable type: Progressing WORKSPACE_STATUS_YAML - ).deep_symbolize_keys + ) end it 'returns the expected actual state' do @@ -164,7 +164,7 @@ context 'when new workspace has been created' do let(:expected_actual_state) { RemoteDevelopment::WorkspaceOperations::States::STARTING } let(:latest_k8s_deployment_info) do - YAML.safe_load( + yaml_safe_load_symbolized( <<~WORKSPACE_STATUS_YAML spec: replicas: 1 @@ -173,7 +173,7 @@ - reason: NewReplicaSetCreated type: Progressing WORKSPACE_STATUS_YAML - ).deep_symbolize_keys + ) end it 'returns the expected actual state' do @@ -185,7 +185,7 @@ context 'when existing workspace has been updated' do let(:expected_actual_state) { RemoteDevelopment::WorkspaceOperations::States::STARTING } let(:latest_k8s_deployment_info) do - YAML.safe_load( + yaml_safe_load_symbolized( <<~WORKSPACE_STATUS_YAML spec: replicas: 1 @@ -194,7 +194,7 @@ - reason: FoundNewReplicaSet type: Progressing WORKSPACE_STATUS_YAML - ).deep_symbolize_keys + ) end it 'returns the expected actual state' do @@ -206,7 +206,7 @@ context 'when existing workspace has been scaled up' do let(:expected_actual_state) { RemoteDevelopment::WorkspaceOperations::States::STARTING } let(:latest_k8s_deployment_info) do - YAML.safe_load( + yaml_safe_load_symbolized( <<~WORKSPACE_STATUS_YAML spec: replicas: 1 @@ -215,7 +215,7 @@ - reason: ReplicaSetUpdated type: Progressing WORKSPACE_STATUS_YAML - ).deep_symbolize_keys + ) end it 'returns the expected actual state' do @@ -227,7 +227,7 @@ context 'when existing workspace has been scaled down' do let(:expected_actual_state) { RemoteDevelopment::WorkspaceOperations::States::STOPPING } let(:latest_k8s_deployment_info) do - YAML.safe_load( + yaml_safe_load_symbolized( <<~WORKSPACE_STATUS_YAML spec: replicas: 0 @@ -236,7 +236,7 @@ - reason: ReplicaSetUpdated type: Progressing WORKSPACE_STATUS_YAML - ).deep_symbolize_keys + ) end it 'returns the expected actual state' do @@ -248,7 +248,7 @@ context 'when spec replicas is more than 1' do let(:expected_actual_state) { RemoteDevelopment::WorkspaceOperations::States::UNKNOWN } let(:latest_k8s_deployment_info) do - YAML.safe_load( + yaml_safe_load_symbolized( <<~WORKSPACE_STATUS_YAML spec: replicas: 2 @@ -257,7 +257,7 @@ - reason: ReplicaSetUpdated type: Progressing WORKSPACE_STATUS_YAML - ).deep_symbolize_keys + ) end it 'returns the expected actual state' do @@ -269,7 +269,7 @@ context 'when status does not contain required information' do let(:expected_actual_state) { RemoteDevelopment::WorkspaceOperations::States::UNKNOWN } let(:latest_k8s_deployment_info) do - YAML.safe_load( + yaml_safe_load_symbolized( <<~WORKSPACE_STATUS_YAML spec: replicas: 1 @@ -278,7 +278,7 @@ - reason: test type: test WORKSPACE_STATUS_YAML - ).deep_symbolize_keys.to_h + ).to_h end it 'returns the expected actual state' do @@ -292,7 +292,7 @@ context 'when new workspace has been created or existing workspace has been scaled up' do let(:expected_actual_state) { RemoteDevelopment::WorkspaceOperations::States::FAILED } let(:latest_k8s_deployment_info) do - YAML.safe_load( + yaml_safe_load_symbolized( <<~WORKSPACE_STATUS_YAML spec: replicas: 1 @@ -304,7 +304,7 @@ type: Progressing unavailableReplicas: 1 WORKSPACE_STATUS_YAML - ).deep_symbolize_keys + ) end it 'returns the expected actual state' do @@ -316,7 +316,7 @@ context 'when existing scaled down workspace which was failing has been scaled up' do let(:expected_actual_state) { RemoteDevelopment::WorkspaceOperations::States::FAILED } let(:latest_k8s_deployment_info) do - YAML.safe_load( + yaml_safe_load_symbolized( <<~WORKSPACE_STATUS_YAML spec: replicas: 1 @@ -328,7 +328,7 @@ type: Progressing unavailableReplicas: 1 WORKSPACE_STATUS_YAML - ).deep_symbolize_keys + ) end it 'returns the expected actual state' do @@ -344,7 +344,7 @@ context 'when spec is missing' do let(:latest_k8s_deployment_info) do - YAML.safe_load( + yaml_safe_load_symbolized( <<~WORKSPACE_STATUS_YAML test: replicas: 0 @@ -353,7 +353,7 @@ - reason: ReplicaSetUpdated type: Progressing WORKSPACE_STATUS_YAML - ).deep_symbolize_keys + ) end it 'returns the expected actual state' do @@ -364,7 +364,7 @@ context 'when spec replicas is missing' do let(:latest_k8s_deployment_info) do - YAML.safe_load( + yaml_safe_load_symbolized( <<~WORKSPACE_STATUS_YAML spec: test: 0 @@ -373,7 +373,7 @@ - reason: ReplicaSetUpdated type: Progressing WORKSPACE_STATUS_YAML - ).deep_symbolize_keys + ) end it 'returns the expected actual state' do @@ -384,12 +384,12 @@ context 'when status is missing' do let(:latest_k8s_deployment_info) do - YAML.safe_load( + yaml_safe_load_symbolized( <<~WORKSPACE_STATUS_YAML spec: replicas: 0 WORKSPACE_STATUS_YAML - ).deep_symbolize_keys + ) end it 'returns the expected actual state' do @@ -400,7 +400,7 @@ context 'when status conditions is missing' do let(:latest_k8s_deployment_info) do - YAML.safe_load( + yaml_safe_load_symbolized( <<~WORKSPACE_STATUS_YAML spec: replicas: 0 @@ -409,7 +409,7 @@ - reason: ReplicaSetUpdated type: Progressing WORKSPACE_STATUS_YAML - ).deep_symbolize_keys + ) end it 'returns the expected actual state' do @@ -420,7 +420,7 @@ context 'when status conditions reason is missing' do let(:latest_k8s_deployment_info) do - YAML.safe_load( + yaml_safe_load_symbolized( <<~WORKSPACE_STATUS_YAML spec: replicas: 0 @@ -428,7 +428,7 @@ conditions: - type: Progressing WORKSPACE_STATUS_YAML - ).deep_symbolize_keys + ) end it 'returns the expected actual state' do @@ -439,7 +439,7 @@ context 'when status progressing and available conditions are unrecognized' do let(:latest_k8s_deployment_info) do - YAML.safe_load( + yaml_safe_load_symbolized( <<~WORKSPACE_STATUS_YAML spec: replicas: 0 @@ -450,7 +450,7 @@ - reason: unrecognized type: Progressing WORKSPACE_STATUS_YAML - ).deep_symbolize_keys + ) end it 'returns the expected actual state' do diff --git a/ee/spec/lib/remote_development/workspace_operations/reconcile/main_integration_spec.rb b/ee/spec/lib/remote_development/workspace_operations/reconcile/main_integration_spec.rb index 8af70426dbeac5..0678cf76c8d377 100644 --- a/ee/spec/lib/remote_development/workspace_operations/reconcile/main_integration_spec.rb +++ b/ee/spec/lib/remote_development/workspace_operations/reconcile/main_integration_spec.rb @@ -37,7 +37,7 @@ config_to_apply = YAML.load_stream(response.dig(:payload, :workspace_rails_infos, 0, :config_to_apply)) - service = config_to_apply.find { |config| config["kind"] == "Service" } + service = config_to_apply.find { |config| config["kind"] == "Service" }.to_h host_template_annotation = service.dig("metadata", "annotations", "workspaces.gitlab.com/host-template") expect(host_template_annotation).to include(dns_zone) @@ -276,7 +276,7 @@ agent: agent, user: user, force_include_all_resources: false) end - let(:invalid_devfile_yaml) { read_devfile('example.invalid-extra-field-devfile.yaml') } + let(:invalid_devfile_yaml) { read_devfile_yaml('example.invalid-extra-field-devfile.yaml') } let(:workspace2_agent_info) do create_workspace_agent_info_hash( diff --git a/ee/spec/lib/remote_development/workspace_operations/reconcile/output/desired_config_generator_v2_spec.rb b/ee/spec/lib/remote_development/workspace_operations/reconcile/output/desired_config_generator_v2_spec.rb index 4034a42c2a9b9b..388db6bc438fd3 100644 --- a/ee/spec/lib/remote_development/workspace_operations/reconcile/output/desired_config_generator_v2_spec.rb +++ b/ee/spec/lib/remote_development/workspace_operations/reconcile/output/desired_config_generator_v2_spec.rb @@ -25,7 +25,7 @@ user: user, desired_state: desired_state, actual_state: actual_state, - processed_devfile: read_devfile('example.processed-devfile-v2.yaml') + processed_devfile: read_devfile_yaml('example.processed-devfile-v2.yaml') ) end diff --git a/ee/spec/lib/remote_development/workspace_operations/reconcile/output/devfile_parser_spec.rb b/ee/spec/lib/remote_development/workspace_operations/reconcile/output/devfile_parser_spec.rb index c77f7d906735d4..9d37b88f59d1b4 100644 --- a/ee/spec/lib/remote_development/workspace_operations/reconcile/output/devfile_parser_spec.rb +++ b/ee/spec/lib/remote_development/workspace_operations/reconcile/output/devfile_parser_spec.rb @@ -24,7 +24,7 @@ deployment_resource_version: "1", desired_state: RemoteDevelopment::WorkspaceOperations::States::RUNNING, actual_state: RemoteDevelopment::WorkspaceOperations::States::STOPPED, - processed_devfile: example_processed_devfile, + processed_devfile: example_processed_devfile_yaml, user: user, agent: agent, workspaces_agent_config: workspaces_agent_config, @@ -34,7 +34,7 @@ end # rubocop:enable RSpec/VerifiedDoubleReference - let(:processed_devfile) { example_processed_devfile } + let(:processed_devfile_yaml) { example_processed_devfile_yaml } let(:domain_template) { "" } let(:egress_ip_rules) do [{ @@ -100,7 +100,7 @@ subject(:k8s_resources_for_workspace_core) do described_class.get_all( - processed_devfile: processed_devfile, + processed_devfile: processed_devfile_yaml, k8s_resources_params: k8s_resources_params, logger: logger ) @@ -115,7 +115,7 @@ 'workspaces.gitlab.com/host-template' => domain_template, 'workspaces.gitlab.com/id' => workspace.id, 'workspaces.gitlab.com/max-resources-per-workspace-sha256' => - Digest::SHA256.hexdigest(max_resources_per_workspace.sort.to_h.to_s) + Digest::SHA256.hexdigest(max_resources_per_workspace.sort.to_h.to_s) }) end @@ -124,7 +124,9 @@ it 'returns workspace_resources with allow_privilege_escalation set to true' do expect(k8s_resources_for_workspace_core).to eq(expected_workspace_resources) - deployment = k8s_resources_for_workspace_core.find { |resource| resource.fetch('kind') == 'Deployment' } + deployment = k8s_resources_for_workspace_core.find do |resource| + resource.fetch('kind') == 'Deployment' + end.to_h container_privilege_escalation = deployment.dig('spec', 'template', 'spec', 'containers').map do |container| container.dig('securityContext', 'allowPrivilegeEscalation') @@ -146,7 +148,9 @@ it 'returns workspace_resources with hostUsers set to true' do expect(k8s_resources_for_workspace_core).to eq(expected_workspace_resources) - deployment = k8s_resources_for_workspace_core.find { |resource| resource.fetch('kind') == 'Deployment' } + deployment = k8s_resources_for_workspace_core.find do |resource| + resource.fetch('kind') == 'Deployment' + end.to_h expect(deployment.dig('spec', 'template', 'spec', 'hostUsers')).to be(true) end end @@ -157,7 +161,7 @@ allow(Devfile::Parser).to receive(:get_all).and_raise(Devfile::CliError.new("some error")) end - let(:processed_devfile) { "" } + let(:processed_devfile_yaml) { "" } it "logs the error" do expect(logger).to receive(:warn).with( diff --git a/ee/spec/lib/remote_development/workspace_operations/reconcile/output/devfile_parser_v2_spec.rb b/ee/spec/lib/remote_development/workspace_operations/reconcile/output/devfile_parser_v2_spec.rb index 20322b4bd69a37..33803df10537c9 100644 --- a/ee/spec/lib/remote_development/workspace_operations/reconcile/output/devfile_parser_v2_spec.rb +++ b/ee/spec/lib/remote_development/workspace_operations/reconcile/output/devfile_parser_v2_spec.rb @@ -9,7 +9,7 @@ let(:logger) { instance_double(Logger) } let(:user) { instance_double("User", name: "name", email: "name@example.com") } # rubocop:disable RSpec/VerifiedDoubleReference -- We're using the quoted version so we can use fast_spec_helper let(:agent) { instance_double("Clusters::Agent", id: 1) } # rubocop:disable RSpec/VerifiedDoubleReference -- We're using the quoted version so we can use fast_spec_helper - let(:processed_devfile) { read_devfile('example.processed-devfile-v2.yaml') } + let(:processed_devfile_yaml) { read_devfile_yaml("example.processed-devfile-v2.yaml") } let(:workspace) do instance_double( "RemoteDevelopment::Workspace", # rubocop:disable RSpec/VerifiedDoubleReference -- We're using the quoted version so we can use fast_spec_helper @@ -19,7 +19,7 @@ deployment_resource_version: "1", desired_state: RemoteDevelopment::WorkspaceOperations::States::RUNNING, actual_state: RemoteDevelopment::WorkspaceOperations::States::STOPPED, - processed_devfile: processed_devfile, + processed_devfile: processed_devfile_yaml, user: user, agent: agent ) @@ -57,7 +57,7 @@ it 'returns workspace_resources' do workspace_resources = devfile_parser.get_all( - processed_devfile: processed_devfile, + processed_devfile: processed_devfile_yaml, name: workspace.name, namespace: workspace.namespace, replicas: 1, 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 5d7a7bfa4e8a3e..b806a1aac936a7 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 @@ -8,7 +8,7 @@ let(:logger) { instance_double(Logger) } let(:desired_state) { RemoteDevelopment::WorkspaceOperations::States::RUNNING } let(:actual_state) { RemoteDevelopment::WorkspaceOperations::States::STOPPED } - let(:processed_devfile) { example_processed_devfile } + let(:processed_devfile_yaml) { example_processed_devfile_yaml } let(:force_include_all_resources) { false } let(:image_pull_secrets) { [{ name: "secret-name", namespace: "secret-namespace" }] } let(:current_desired_config_generator_version) do @@ -35,7 +35,7 @@ deployment_resource_version: "1", desired_state: desired_state, actual_state: actual_state, - processed_devfile: processed_devfile, + processed_devfile: processed_devfile_yaml, desired_config_generator_version: desired_config_generator_version, force_include_all_resources: force_include_all_resources, workspaces_agent_config: agent_config diff --git a/ee/spec/requests/remote_development/integration_spec.rb b/ee/spec/requests/remote_development/integration_spec.rb index da0b1dfd3edad7..b0c4a7f26fbad8 100644 --- a/ee/spec/requests/remote_development/integration_spec.rb +++ b/ee/spec/requests/remote_development/integration_spec.rb @@ -64,7 +64,7 @@ let(:devfile_path) { ".devfile.yaml" } let(:devfile_fixture_name) { "example.devfile.yaml" } let(:devfile_yaml) do - read_devfile( + read_devfile_yaml( devfile_fixture_name, namespace_path: "#{common_parent_namespace_name}/#{workspace_project_namespace_name}", project_name: workspace_project_name @@ -72,13 +72,13 @@ end let(:expected_processed_devfile_yaml) do - example_processed_devfile( + example_processed_devfile_yaml( namespace_path: "#{common_parent_namespace_name}/#{workspace_project_namespace_name}", project_name: workspace_project_name ) end - let(:expected_processed_devfile) { YAML.safe_load(expected_processed_devfile_yaml).to_h } + let(:expected_processed_devfile) { yaml_safe_load_symbolized(expected_processed_devfile_yaml) } let(:workspace_root) { "/projects" } let(:user_provided_variables) do [ @@ -233,8 +233,8 @@ def do_create_workspace }).to_s) # noinspection RubyResolve expect(workspace.devfile).to eq(devfile_yaml) - actual_processed_devfile = YAML.safe_load(workspace.processed_devfile).to_h - expect(actual_processed_devfile.fetch("components")).to eq(expected_processed_devfile.fetch("components")) + actual_processed_devfile = yaml_safe_load_symbolized(workspace.processed_devfile) + expect(actual_processed_devfile.fetch(:components)).to eq(expected_processed_devfile.fetch(:components)) expect(actual_processed_devfile).to eq(expected_processed_devfile) all_expected_vars = (expected_static_variables + user_provided_variables).sort_by { |v| v[:key] } 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 a949fda519a03d..9f89586c5db3e5 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 @@ -1231,21 +1231,37 @@ def get_workspace_host_template_environment(workspace_name, dns_zone) "${PORT}-#{workspace_name}.#{dns_zone}" end + def yaml_safe_load_symbolized(yaml) + YAML.safe_load(yaml).to_h.deep_symbolize_keys + end + + def example_devfile_yaml + read_devfile_yaml('example.devfile.yaml') + end + def example_devfile - read_devfile('example.devfile.yaml') + yaml_safe_load_symbolized(example_devfile_yaml) + end + + def example_flattened_devfile_yaml + read_devfile_yaml("example.flattened-devfile.yaml") end def example_flattened_devfile - read_devfile('example.flattened-devfile.yaml') + yaml_safe_load_symbolized(example_flattened_devfile_yaml) + end + + 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) end def example_processed_devfile(project_name: "test-project", namespace_path: "test-group") - read_devfile('example.processed-devfile.yaml', project_name: project_name, namespace_path: namespace_path) + yaml_safe_load_symbolized( + example_processed_devfile_yaml(project_name: project_name, namespace_path: namespace_path) + ) end - # TODO: Rename this method and all methods which use it to end in `_yaml`, to clearly distinguish between - # a String YAML representation of a devfile, and a devfile which has been converted to a Hash. - def read_devfile(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.gsub!('http://localhost/', root_url) devfile_contents.gsub!('test-project', project_name) -- GitLab From 0e73e4e43d5dafcd125f5f7b14e4ed6ce9fe577c Mon Sep 17 00:00:00 2001 From: Chad Woolley Date: Fri, 13 Dec 2024 19:45:38 +0530 Subject: [PATCH 2/2] Review feedback --- .../workspace_operations/create/main_component_updater.rb | 2 +- .../create/post_flatten_devfile_validator.rb | 5 +++-- .../workspace_operations/create/volume_component_inserter.rb | 2 +- .../workspace_operations/create/main_integration_spec.rb | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ee/lib/remote_development/workspace_operations/create/main_component_updater.rb b/ee/lib/remote_development/workspace_operations/create/main_component_updater.rb index 91a3ce50926ee1..17a9bbc49bbc2a 100644 --- a/ee/lib/remote_development/workspace_operations/create/main_component_updater.rb +++ b/ee/lib/remote_development/workspace_operations/create/main_component_updater.rb @@ -23,7 +23,7 @@ def self.update(context) # NOTE: We will always have exactly one main_component found, because we have already # validated this in post_flatten_devfile_validator.rb - main_component = processed_devfile[:components].find { |c| c.dig(:attributes, :'gl/inject-editor') } + main_component = processed_devfile.fetch(:components).find { |c| c.dig(:attributes, :'gl/inject-editor') } update_main_container( main_component: main_component, diff --git a/ee/lib/remote_development/workspace_operations/create/post_flatten_devfile_validator.rb b/ee/lib/remote_development/workspace_operations/create/post_flatten_devfile_validator.rb index e823fbfef51a69..c1d3ab8fcc0d8f 100644 --- a/ee/lib/remote_development/workspace_operations/create/post_flatten_devfile_validator.rb +++ b/ee/lib/remote_development/workspace_operations/create/post_flatten_devfile_validator.rb @@ -148,9 +148,10 @@ def self.validate_endpoints(context) err_result = nil components.each do |component| - container = component[:container] next unless component.dig(:container, :endpoints) + container = component.fetch(:container) + container.fetch(:endpoints).each do |endpoint| endpoint_name = endpoint.fetch(:name) next unless endpoint_name.downcase.start_with?(RESTRICTED_PREFIX) @@ -194,7 +195,7 @@ def self.validate_commands(context) command_type = command[supported_command_type] next unless command_type - component_name = command_type[:component] + component_name = command_type.fetch(:component) next unless component_name.downcase.start_with?(RESTRICTED_PREFIX) return err( diff --git a/ee/lib/remote_development/workspace_operations/create/volume_component_inserter.rb b/ee/lib/remote_development/workspace_operations/create/volume_component_inserter.rb index be177c94ebfa7a..a1b3635c1070a6 100644 --- a/ee/lib/remote_development/workspace_operations/create/volume_component_inserter.rb +++ b/ee/lib/remote_development/workspace_operations/create/volume_component_inserter.rb @@ -23,7 +23,7 @@ def self.insert(context) } } - components = processed_devfile[:components] + components = processed_devfile.fetch(:components) components << volume_component components.each do |component| diff --git a/ee/spec/lib/remote_development/workspace_operations/create/main_integration_spec.rb b/ee/spec/lib/remote_development/workspace_operations/create/main_integration_spec.rb index 354375b17c3360..4cf08dc967b865 100644 --- a/ee/spec/lib/remote_development/workspace_operations/create/main_integration_spec.rb +++ b/ee/spec/lib/remote_development/workspace_operations/create/main_integration_spec.rb @@ -218,7 +218,7 @@ workspace = response.fetch(:payload).fetch(:workspace) processed_devfile = yaml_safe_load_symbolized(workspace.processed_devfile) image_from_processed_devfile = - processed_devfile[:components] + processed_devfile.fetch(:components) .find { |component| component.fetch(:name) == "gl-tools-injector" } .dig(:container, :image) expect(image_from_processed_devfile).to eq(tools_injector_image_from_settings) -- GitLab