From c35e385bbbb0052e8ff225d74e94eb2c6cf76c57 Mon Sep 17 00:00:00 2001 From: Vishal Tak Date: Mon, 29 Jan 2024 11:14:30 +0530 Subject: [PATCH] Fix bug for devfile with multiple container components Simplify specs to extract out the intermediate devfile that is generated. --- .../workspaces/create/main.rb | 2 +- .../project_cloner_component_injector.rb | 9 +- .../create/tools_component_injector.rb | 45 +++------- .../create/volume_component_injector.rb | 15 +++- .../remote_development/example.devfile.yaml | 7 ++ .../example.flattened-devfile.yaml | 8 ++ .../example.processed-devfile-v2.yaml | 17 +++- .../example.processed-devfile.yaml | 17 +++- ...ample.project-cloner-injected-devfile.yaml | 90 +++++++++++++++++++ .../example.tools-injected-devfile.yaml | 70 +++++++++++++++ ...injected-marketplace-disabled-devfile.yaml | 70 +++++++++++++++ .../project_cloner_component_injector_spec.rb | 19 ++-- .../create/tools_component_injector_spec.rb | 33 +++---- .../create/volume_component_injector_spec.rb | 17 ++-- .../remote_development_shared_contexts.rb | 43 +++++++++ 15 files changed, 367 insertions(+), 95 deletions(-) create mode 100644 ee/spec/fixtures/remote_development/example.project-cloner-injected-devfile.yaml create mode 100644 ee/spec/fixtures/remote_development/example.tools-injected-devfile.yaml create mode 100644 ee/spec/fixtures/remote_development/example.tools-injected-marketplace-disabled-devfile.yaml diff --git a/ee/lib/remote_development/workspaces/create/main.rb b/ee/lib/remote_development/workspaces/create/main.rb index d63ae6c0022434..396e86b887b75e 100644 --- a/ee/lib/remote_development/workspaces/create/main.rb +++ b/ee/lib/remote_development/workspaces/create/main.rb @@ -23,9 +23,9 @@ def self.main(value) .and_then(DevfileFlattener.method(:flatten)) .and_then(PostFlattenDevfileValidator.method(:validate)) .map(VolumeDefiner.method(:define)) - .map(VolumeComponentInjector.method(:inject)) .map(ToolsComponentInjector.method(:inject)) .map(ProjectClonerComponentInjector.method(:inject)) + .map(VolumeComponentInjector.method(:inject)) .and_then(Creator.method(:create)) # rubocop:disable Lint/DuplicateBranch -- Rubocop doesn't know the branches are different due to destructuring diff --git a/ee/lib/remote_development/workspaces/create/project_cloner_component_injector.rb b/ee/lib/remote_development/workspaces/create/project_cloner_component_injector.rb index 0554d563b3eda6..36b4f11bce16a1 100644 --- a/ee/lib/remote_development/workspaces/create/project_cloner_component_injector.rb +++ b/ee/lib/remote_development/workspaces/create/project_cloner_component_injector.rb @@ -15,12 +15,8 @@ def self.inject(value) params: Hash => params } volume_mounts => { data_volume: Hash => data_volume } - data_volume => { - name: String => volume_name, - path: String => volume_path, - } - - params => {project: Project => project} + data_volume => { path: String => volume_path } + params => { project: Project => project } # TODO: https://gitlab.com/gitlab-org/gitlab/-/issues/408448 # replace the alpine/git docker image with one that is published by gitlab for security / reliability @@ -52,7 +48,6 @@ def self.inject(value) 'name' => 'gl-cloner-injector', 'container' => { 'image' => "#{image_name}:#{image_tag}", - 'volumeMounts' => [{ 'name' => volume_name, 'path' => volume_path }], 'args' => [container_args], # command has been overridden here as the default command in the alpine/git # container invokes git directly diff --git a/ee/lib/remote_development/workspaces/create/tools_component_injector.rb b/ee/lib/remote_development/workspaces/create/tools_component_injector.rb index eedc12d49b727d..b8637e3cec1cb8 100644 --- a/ee/lib/remote_development/workspaces/create/tools_component_injector.rb +++ b/ee/lib/remote_development/workspaces/create/tools_component_injector.rb @@ -15,31 +15,25 @@ def self.inject(value) params: Hash => params } volume_mounts => { data_volume: Hash => data_volume } - data_volume => { - name: String => volume_name, - path: String => volume_path, - } - - params => { - agent: Clusters::Agent => agent - } + data_volume => { path: String => volume_path } + params => { agent: Clusters::Agent => agent } editor_port = WorkspaceCreator::WORKSPACE_PORT ssh_port = 60022 + tools_dir = "#{volume_path}/.gl-tools" enable_marketplace = Feature.enabled?( :allow_extensions_marketplace_in_workspace, agent.project.root_namespace, type: :beta ) - inject_tools_component(processed_devfile, volume_name, volume_path) + inject_tools_component(processed_devfile, tools_dir) tools_component = processed_devfile['components'].find { |c| c.dig('attributes', 'gl/inject-editor') } if tools_component override_main_container( tools_component, - volume_name, - volume_path, + tools_dir, editor_port, ssh_port, enable_marketplace @@ -50,13 +44,12 @@ def self.inject(value) end # @param [Hash] component - # @param [String] volume_name - # @param [String] volume_path + # @param [String] tools_dir # @param [Integer] editor_port # @param [Integer] ssh_port # @param [Boolean] enable_marketplace # @return [Hash] - def self.override_main_container(component, volume_name, volume_path, editor_port, ssh_port, enable_marketplace) + def self.override_main_container(component, tools_dir, editor_port, ssh_port, enable_marketplace) # This overrides the main container's command # Open issue to support both starting the editor and running the default command: # https://gitlab.com/gitlab-org/gitlab/-/issues/392853 @@ -72,17 +65,11 @@ def self.override_main_container(component, volume_name, volume_path, editor_por SH component['container']['command'] = %w[/bin/sh -c] component['container']['args'] = [container_args] - - component['container']['volumeMounts'] = [] if component['container']['volumeMounts'].nil? - - component['container']['volumeMounts'] += [{ 'name' => volume_name, 'path' => volume_path }] - component['container']['env'] = [] if component['container']['env'].nil? - component['container']['env'] += [ { 'name' => 'GL_TOOLS_DIR', - 'value' => "#{volume_path}/.gl-tools" + 'value' => tools_dir }, { 'name' => 'GL_EDITOR_LOG_LEVEL', @@ -103,7 +90,6 @@ def self.override_main_container(component, volume_name, volume_path, editor_por ] component['container']['endpoints'] = [] if component['container']['endpoints'].nil? - component['container']['endpoints'].append( { 'name' => 'editor-server', @@ -123,11 +109,10 @@ def self.override_main_container(component, volume_name, volume_path, editor_por end # @param [Hash] processed_devfile - # @param [String] volume_name - # @param [String] volume_path + # @param [String] tools_dir # @return [Array] - def self.inject_tools_component(processed_devfile, volume_name, volume_path) - processed_devfile['components'] += tools_components(volume_name, volume_path) + def self.inject_tools_component(processed_devfile, tools_dir) + processed_devfile['components'] += tools_components(tools_dir) processed_devfile['commands'] = [] if processed_devfile['commands'].nil? processed_devfile['commands'] += [{ @@ -142,10 +127,9 @@ def self.inject_tools_component(processed_devfile, volume_name, volume_path) processed_devfile['events']['preStart'] += ['gl-tools-injector-command'] end - # @param [String] volume_name - # @param [String] volume_path + # @param [String] tools_dir # @return [Array] - def self.tools_components(volume_name, volume_path) + def self.tools_components(tools_dir) # TODO: https://gitlab.com/gitlab-org/gitlab/-/issues/409775 - choose image based on which editor is passed. image_name = 'registry.gitlab.com/gitlab-org/gitlab-web-ide-vscode-fork/web-ide-injector' image_tag = '7' @@ -155,11 +139,10 @@ def self.tools_components(volume_name, volume_path) 'name' => 'gl-tools-injector', 'container' => { 'image' => "#{image_name}:#{image_tag}", - 'volumeMounts' => [{ 'name' => volume_name, 'path' => volume_path }], 'env' => [ { 'name' => 'GL_TOOLS_DIR', - 'value' => "#{volume_path}/.gl-tools" + 'value' => tools_dir } ], 'memoryLimit' => '256Mi', diff --git a/ee/lib/remote_development/workspaces/create/volume_component_injector.rb b/ee/lib/remote_development/workspaces/create/volume_component_injector.rb index 2d54aad5c678c3..9ebebeb02acfaa 100644 --- a/ee/lib/remote_development/workspaces/create/volume_component_injector.rb +++ b/ee/lib/remote_development/workspaces/create/volume_component_injector.rb @@ -11,16 +11,25 @@ class VolumeComponentInjector def self.inject(value) value => { processed_devfile: Hash => processed_devfile, volume_mounts: Hash => volume_mounts } volume_mounts => { data_volume: Hash => data_volume } - data_volume => { name: String => volume_name } + data_volume => { + name: String => volume_name, + path: String => volume_path, + } - component = { + volume_component = { 'name' => volume_name, 'volume' => { 'size' => '15Gi' } } - processed_devfile['components'] << component + processed_devfile['components'] << volume_component + processed_devfile['components'].each do |component| + next if component['container'].nil? + + component['container']['volumeMounts'] = [] if component['container']['volumeMounts'].nil? + component['container']['volumeMounts'] += [{ 'name' => volume_name, 'path' => volume_path }] + end value end diff --git a/ee/spec/fixtures/remote_development/example.devfile.yaml b/ee/spec/fixtures/remote_development/example.devfile.yaml index b0b397aef5458a..cae2fcd1d74330 100644 --- a/ee/spec/fixtures/remote_development/example.devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.devfile.yaml @@ -6,3 +6,10 @@ components: gl/inject-editor: true container: image: quay.io/mloriedo/universal-developer-image:ubi8-dw-demo + - name: database-container + container: + image: mysql + env: + - name: MYSQL_ROOT_PASSWORD + value: "my-secret-pw" + diff --git a/ee/spec/fixtures/remote_development/example.flattened-devfile.yaml b/ee/spec/fixtures/remote_development/example.flattened-devfile.yaml index 4b8559d875a2fc..397a5b7e9be0bd 100644 --- a/ee/spec/fixtures/remote_development/example.flattened-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.flattened-devfile.yaml @@ -9,3 +9,11 @@ components: dedicatedPod: false mountSources: true image: quay.io/mloriedo/universal-developer-image:ubi8-dw-demo + - name: database-container + container: + dedicatedPod: false + mountSources: true + image: mysql + env: + - name: MYSQL_ROOT_PASSWORD + value: "my-secret-pw" 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 6dce360cdbc84a..97affea3f86264 100644 --- a/ee/spec/fixtures/remote_development/example.processed-devfile-v2.yaml +++ b/ee/spec/fixtures/remote_development/example.processed-devfile-v2.yaml @@ -46,9 +46,17 @@ components: secure: true dedicatedPod: false mountSources: true - - name: gl-workspace-data - volume: - size: 15Gi + - name: database-container + container: + image: mysql + volumeMounts: + - name: gl-workspace-data + path: /projects + env: + - name: MYSQL_ROOT_PASSWORD + value: "my-secret-pw" + dedicatedPod: false + mountSources: true - name: gl-tools-injector container: image: registry.gitlab.com/gitlab-org/gitlab-web-ide-vscode-fork/web-ide-injector:7 @@ -81,6 +89,9 @@ components: memoryRequest: 128Mi cpuLimit: 500m cpuRequest: 100m + - name: gl-workspace-data + volume: + size: 15Gi events: preStart: - gl-tools-injector-command diff --git a/ee/spec/fixtures/remote_development/example.processed-devfile.yaml b/ee/spec/fixtures/remote_development/example.processed-devfile.yaml index 6dce360cdbc84a..97affea3f86264 100644 --- a/ee/spec/fixtures/remote_development/example.processed-devfile.yaml +++ b/ee/spec/fixtures/remote_development/example.processed-devfile.yaml @@ -46,9 +46,17 @@ components: secure: true dedicatedPod: false mountSources: true - - name: gl-workspace-data - volume: - size: 15Gi + - name: database-container + container: + image: mysql + volumeMounts: + - name: gl-workspace-data + path: /projects + env: + - name: MYSQL_ROOT_PASSWORD + value: "my-secret-pw" + dedicatedPod: false + mountSources: true - name: gl-tools-injector container: image: registry.gitlab.com/gitlab-org/gitlab-web-ide-vscode-fork/web-ide-injector:7 @@ -81,6 +89,9 @@ components: memoryRequest: 128Mi cpuLimit: 500m cpuRequest: 100m + - name: gl-workspace-data + volume: + size: 15Gi events: preStart: - gl-tools-injector-command diff --git a/ee/spec/fixtures/remote_development/example.project-cloner-injected-devfile.yaml b/ee/spec/fixtures/remote_development/example.project-cloner-injected-devfile.yaml new file mode 100644 index 00000000000000..88d6d9c2fc3fd6 --- /dev/null +++ b/ee/spec/fixtures/remote_development/example.project-cloner-injected-devfile.yaml @@ -0,0 +1,90 @@ +--- +schemaVersion: 2.2.0 +metadata: {} +components: + - name: tooling-container + attributes: + gl/inject-editor: true + container: + image: quay.io/mloriedo/universal-developer-image:ubi8-dw-demo + args: + - |- + sshd_path=$(which sshd) + if [ -x "$sshd_path" ]; then + echo "Starting sshd on port ${GL_SSH_PORT}" + $sshd_path -D -p $GL_SSH_PORT & + else + echo "'sshd' not found in path. Not starting SSH server." + fi + ${GL_TOOLS_DIR}/init_tools.sh + command: + - "/bin/sh" + - "-c" + env: + - name: GL_TOOLS_DIR + value: "/projects/.gl-tools" + - name: GL_EDITOR_LOG_LEVEL + value: "info" + - name: GL_EDITOR_PORT + value: "60001" + - name: GL_SSH_PORT + value: "60022" + - name: GL_EDITOR_ENABLE_MARKETPLACE + value: "true" + endpoints: + - name: editor-server + targetPort: 60001 + exposure: public + secure: true + protocol: https + - name: ssh-server + targetPort: 60022 + exposure: internal + secure: true + dedicatedPod: false + mountSources: true + - name: database-container + container: + image: mysql + env: + - name: MYSQL_ROOT_PASSWORD + value: "my-secret-pw" + dedicatedPod: false + mountSources: true + - name: gl-tools-injector + container: + image: registry.gitlab.com/gitlab-org/gitlab-web-ide-vscode-fork/web-ide-injector:7 + env: + - name: GL_TOOLS_DIR + value: "/projects/.gl-tools" + memoryLimit: 256Mi + memoryRequest: 128Mi + cpuLimit: 500m + cpuRequest: 100m + - name: gl-cloner-injector + container: + image: alpine/git:2.36.3 + args: + - |- + if [ ! -d '/projects/test-project' ]; + then + git clone --branch master http://localhost/test-group/test-project.git /projects/test-project; + fi + command: + - "/bin/sh" + - "-c" + memoryLimit: 256Mi + memoryRequest: 128Mi + cpuLimit: 500m + cpuRequest: 100m +events: + preStart: + - gl-tools-injector-command + - gl-cloner-injector-command +commands: + - id: gl-tools-injector-command + apply: + component: gl-tools-injector + - id: gl-cloner-injector-command + apply: + component: gl-cloner-injector diff --git a/ee/spec/fixtures/remote_development/example.tools-injected-devfile.yaml b/ee/spec/fixtures/remote_development/example.tools-injected-devfile.yaml new file mode 100644 index 00000000000000..c97c2ceca7c8c5 --- /dev/null +++ b/ee/spec/fixtures/remote_development/example.tools-injected-devfile.yaml @@ -0,0 +1,70 @@ +--- +schemaVersion: 2.2.0 +metadata: {} +components: + - name: tooling-container + attributes: + gl/inject-editor: true + container: + image: quay.io/mloriedo/universal-developer-image:ubi8-dw-demo + args: + - |- + sshd_path=$(which sshd) + if [ -x "$sshd_path" ]; then + echo "Starting sshd on port ${GL_SSH_PORT}" + $sshd_path -D -p $GL_SSH_PORT & + else + echo "'sshd' not found in path. Not starting SSH server." + fi + ${GL_TOOLS_DIR}/init_tools.sh + command: + - "/bin/sh" + - "-c" + env: + - name: GL_TOOLS_DIR + value: "/projects/.gl-tools" + - name: GL_EDITOR_LOG_LEVEL + value: "info" + - name: GL_EDITOR_PORT + value: "60001" + - name: GL_SSH_PORT + value: "60022" + - name: GL_EDITOR_ENABLE_MARKETPLACE + value: "true" + endpoints: + - name: editor-server + targetPort: 60001 + exposure: public + secure: true + protocol: https + - name: ssh-server + targetPort: 60022 + exposure: internal + secure: true + dedicatedPod: false + mountSources: true + - name: database-container + container: + image: mysql + env: + - name: MYSQL_ROOT_PASSWORD + value: "my-secret-pw" + dedicatedPod: false + mountSources: true + - name: gl-tools-injector + container: + image: registry.gitlab.com/gitlab-org/gitlab-web-ide-vscode-fork/web-ide-injector:7 + env: + - name: GL_TOOLS_DIR + value: "/projects/.gl-tools" + memoryLimit: 256Mi + memoryRequest: 128Mi + cpuLimit: 500m + cpuRequest: 100m +events: + preStart: + - gl-tools-injector-command +commands: + - id: gl-tools-injector-command + apply: + component: gl-tools-injector diff --git a/ee/spec/fixtures/remote_development/example.tools-injected-marketplace-disabled-devfile.yaml b/ee/spec/fixtures/remote_development/example.tools-injected-marketplace-disabled-devfile.yaml new file mode 100644 index 00000000000000..71879891b38003 --- /dev/null +++ b/ee/spec/fixtures/remote_development/example.tools-injected-marketplace-disabled-devfile.yaml @@ -0,0 +1,70 @@ +--- +schemaVersion: 2.2.0 +metadata: {} +components: + - name: tooling-container + attributes: + gl/inject-editor: true + container: + image: quay.io/mloriedo/universal-developer-image:ubi8-dw-demo + args: + - |- + sshd_path=$(which sshd) + if [ -x "$sshd_path" ]; then + echo "Starting sshd on port ${GL_SSH_PORT}" + $sshd_path -D -p $GL_SSH_PORT & + else + echo "'sshd' not found in path. Not starting SSH server." + fi + ${GL_TOOLS_DIR}/init_tools.sh + command: + - "/bin/sh" + - "-c" + env: + - name: GL_TOOLS_DIR + value: "/projects/.gl-tools" + - name: GL_EDITOR_LOG_LEVEL + value: "info" + - name: GL_EDITOR_PORT + value: "60001" + - name: GL_SSH_PORT + value: "60022" + - name: GL_EDITOR_ENABLE_MARKETPLACE + value: "false" + endpoints: + - name: editor-server + targetPort: 60001 + exposure: public + secure: true + protocol: https + - name: ssh-server + targetPort: 60022 + exposure: internal + secure: true + dedicatedPod: false + mountSources: true + - name: database-container + container: + image: mysql + env: + - name: MYSQL_ROOT_PASSWORD + value: "my-secret-pw" + dedicatedPod: false + mountSources: true + - name: gl-tools-injector + container: + image: registry.gitlab.com/gitlab-org/gitlab-web-ide-vscode-fork/web-ide-injector:7 + env: + - name: GL_TOOLS_DIR + value: "/projects/.gl-tools" + memoryLimit: 256Mi + memoryRequest: 128Mi + cpuLimit: 500m + cpuRequest: 100m +events: + preStart: + - gl-tools-injector-command +commands: + - id: gl-tools-injector-command + apply: + component: gl-tools-injector diff --git a/ee/spec/lib/remote_development/workspaces/create/project_cloner_component_injector_spec.rb b/ee/spec/lib/remote_development/workspaces/create/project_cloner_component_injector_spec.rb index 7362e23a9e88c1..d35515347fc37f 100644 --- a/ee/spec/lib/remote_development/workspaces/create/project_cloner_component_injector_spec.rb +++ b/ee/spec/lib/remote_development/workspaces/create/project_cloner_component_injector_spec.rb @@ -10,20 +10,19 @@ create(:project, :in_group, :repository, path: "test-project", namespace: group) end - let(:flattened_devfile_name) { 'example.flattened-devfile.yaml' } - let(:processed_devfile) { YAML.safe_load(read_devfile(flattened_devfile_name)) } - let(:expected_processed_devfile) { YAML.safe_load(example_processed_devfile) } + let(:input_processed_devfile_name) { 'example.tools-injected-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-injected-devfile.yaml' } + let(:expected_processed_devfile) { YAML.safe_load(read_devfile(expected_processed_devfile_name)).to_h } let(:component_name) { "gl-cloner-injector" } - let(:volume_name) { "gl-workspace-data" } let(:value) do { params: { project: project }, - processed_devfile: processed_devfile, + processed_devfile: input_processed_devfile, volume_mounts: { data_volume: { - name: volume_name, path: "/projects" } } @@ -35,12 +34,6 @@ end it "injects the project cloner component" do - components = returned_value.dig(:processed_devfile, "components") - project_cloner_component = components.find { |component| component.fetch("name") == component_name } - expected_components = expected_processed_devfile.fetch("components") - expected_volume_component = expected_components.find do |component| - component.fetch("name") == component_name - end - expect(project_cloner_component).to eq(expected_volume_component) + expect(returned_value[:processed_devfile]).to eq(expected_processed_devfile) end end diff --git a/ee/spec/lib/remote_development/workspaces/create/tools_component_injector_spec.rb b/ee/spec/lib/remote_development/workspaces/create/tools_component_injector_spec.rb index 4a7ed9a4ba5e95..1c7dea278e161f 100644 --- a/ee/spec/lib/remote_development/workspaces/create/tools_component_injector_spec.rb +++ b/ee/spec/lib/remote_development/workspaces/create/tools_component_injector_spec.rb @@ -6,11 +6,10 @@ include_context 'with remote development shared fixtures' let(:agent) { create(:ee_cluster_agent, :with_remote_development_agent_config) } - let(:flattened_devfile_name) { 'example.flattened-devfile.yaml' } - let(:input_processed_devfile) { YAML.safe_load(read_devfile(flattened_devfile_name)).to_h } - let(:processed_devfile_name) { 'example.processed-devfile.yaml' } - let(:expected_processed_devfile) { YAML.safe_load(read_devfile(processed_devfile_name)).to_h } - let(:volume_name) { 'gl-workspace-data' } + 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-injected-devfile.yaml' } + let(:expected_processed_devfile) { YAML.safe_load(read_devfile(expected_processed_devfile_name)).to_h } let(:value) do { params: { @@ -19,7 +18,6 @@ processed_devfile: input_processed_devfile, volume_mounts: { data_volume: { - name: volume_name, path: "/projects" } } @@ -30,30 +28,19 @@ described_class.inject(value) end - shared_examples 'successful injection of tools components' do - it 'injects the tools injector component' do - components = returned_value.dig(:processed_devfile, 'components') - tools_component = components.find { |c| c.dig('attributes', 'gl/inject-editor') } - tools_injector_component = components.find { |c| c.fetch('name') == 'gl-tools-injector' } - relevant_components = [tools_component, tools_injector_component] - relevant_components_name = relevant_components.map { |c| c.fetch('name') } - processed_devfile_components = expected_processed_devfile.fetch('components') - expected_relevant_components = processed_devfile_components.select do |component| - relevant_components_name.include? component.fetch('name') - end - expect(relevant_components).to eq(expected_relevant_components) - end + it 'injects the tools injector component' do + expect(returned_value[:processed_devfile]).to eq(expected_processed_devfile) end - it_behaves_like 'successful injection of tools components' - context "when allow_extensions_marketplace_in_workspace is disabled" do - let(:processed_devfile_name) { 'example.processed-marketplace-disabled-devfile.yaml' } + let(:expected_processed_devfile_name) { 'example.tools-injected-marketplace-disabled-devfile.yaml' } before do stub_feature_flags(allow_extensions_marketplace_in_workspace: false) end - it_behaves_like 'successful injection of tools components' + it 'injects the tools injector component' do + expect(returned_value[:processed_devfile]).to eq(expected_processed_devfile) + end end end diff --git a/ee/spec/lib/remote_development/workspaces/create/volume_component_injector_spec.rb b/ee/spec/lib/remote_development/workspaces/create/volume_component_injector_spec.rb index 442ecfd894e372..eff3e5dce3717c 100644 --- a/ee/spec/lib/remote_development/workspaces/create/volume_component_injector_spec.rb +++ b/ee/spec/lib/remote_development/workspaces/create/volume_component_injector_spec.rb @@ -5,14 +5,15 @@ RSpec.describe RemoteDevelopment::Workspaces::Create::VolumeComponentInjector, feature_category: :remote_development do include_context 'with remote development shared fixtures' - let(:flattened_devfile_name) { 'example.flattened-devfile.yaml' } - let(:processed_devfile) { YAML.safe_load(read_devfile(flattened_devfile_name)).to_h } - let(:expected_processed_devfile) { YAML.safe_load(example_processed_devfile) } + let(:input_processed_devfile_name) { 'example.project-cloner-injected-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(:component_name) { "gl-workspace-data" } let(:volume_name) { "gl-workspace-data" } let(:value) do { - processed_devfile: processed_devfile, + processed_devfile: input_processed_devfile, volume_mounts: { data_volume: { name: volume_name, @@ -27,12 +28,6 @@ end it "injects the workspace volume component" do - components = returned_value.dig(:processed_devfile, "components") - volume_component = components.find { |component| component.fetch("name") == component_name } - expected_components = expected_processed_devfile.fetch("components") - expected_volume_component = expected_components.find do |component| - component.fetch("name") == component_name - end - expect(volume_component).to eq(expected_volume_component) + expect(returned_value[:processed_devfile]).to eq(expected_processed_devfile) end end diff --git a/ee/spec/support/shared_contexts/remote_development/remote_development_shared_contexts.rb b/ee/spec/support/shared_contexts/remote_development/remote_development_shared_contexts.rb index d1875606558a8a..f26a834f6e7d65 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 @@ -670,6 +670,49 @@ def workspace_deployment( } } ] + }, + { + env: [ + { + name: "MYSQL_ROOT_PASSWORD", + value: "my-secret-pw" + }, + { + name: "PROJECTS_ROOT", + value: "/projects" + }, + { + name: "PROJECT_SOURCE", + value: "/projects" + } + ], + image: "mysql", + imagePullPolicy: "Always", + name: "database-container", + resources: default_resources_per_workspace_container, + volumeMounts: [ + { + mountPath: "/projects", + name: "gl-workspace-data" + }, + { + name: "gl-workspace-variables", + mountPath: variables_file_mount_path.to_s + } + ], + securityContext: { + allowPrivilegeEscalation: false, + privileged: false, + runAsNonRoot: true, + runAsUser: 5001 + }, + envFrom: [ + { + secretRef: { + name: "#{workspace_name}-env-var" + } + } + ] } ], initContainers: [ -- GitLab