Class: Gitlab::BackgroundMigration::RemoteDevelopment::WorkspaceOperations::Create::DesiredConfig::BmKubernetesPoststartHookInserter
- Inherits:
-
Object
- Object
- Gitlab::BackgroundMigration::RemoteDevelopment::WorkspaceOperations::Create::DesiredConfig::BmKubernetesPoststartHookInserter
- Includes:
- BmFiles, BmCreateConstants
- Defined in:
- lib/gitlab/background_migration/remote_development/workspace_operations/create/desired_config/bm_kubernetes_poststart_hook_inserter.rb
Overview
NOTE: This class has “Kubernetes” prepended to “Poststart” in the name to make it explicit that it
deals with Kubernetes postStart hooks in the Kubernetes Deployment resource, and that
it is NOT dealing with the postStart events which are found in devfiles.
Constant Summary
Constants included from BmCreateConstants
BmCreateConstants::CLONE_DEPTH_OPTION, BmCreateConstants::GIT_CREDENTIAL_STORE_SCRIPT_FILE_NAME, BmCreateConstants::GIT_CREDENTIAL_STORE_SCRIPT_FILE_PATH, BmCreateConstants::LEGACY_RUN_POSTSTART_COMMANDS_SCRIPT_NAME, BmCreateConstants::NAMESPACE_PREFIX, BmCreateConstants::PROJECT_CLONING_SUCCESSFUL_FILE_NAME, BmCreateConstants::RUN_AS_USER, BmCreateConstants::RUN_INTERNAL_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME, BmCreateConstants::RUN_NON_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME, BmCreateConstants::TOKEN_FILE_NAME, BmCreateConstants::TOKEN_FILE_PATH, BmCreateConstants::TOOLS_DIR_ENV_VAR, BmCreateConstants::TOOLS_DIR_NAME, BmCreateConstants::TOOLS_INJECTOR_COMPONENT_NAME, BmCreateConstants::WORKSPACE_DATA_VOLUME_NAME, BmCreateConstants::WORKSPACE_EDITOR_PORT, BmCreateConstants::WORKSPACE_SCRIPTS_VOLUME_DEFAULT_MODE, BmCreateConstants::WORKSPACE_SCRIPTS_VOLUME_NAME, BmCreateConstants::WORKSPACE_SCRIPTS_VOLUME_PATH, BmCreateConstants::WORKSPACE_SSH_PORT
Constants included from BmWorkspaceOperationsConstants
BmWorkspaceOperationsConstants::ANNOTATION_KEY_INCLUDE_IN_PARTIAL_RECONCILIATION, BmWorkspaceOperationsConstants::ENV_VAR_SECRET_SUFFIX, BmWorkspaceOperationsConstants::FILE_SECRET_SUFFIX, BmWorkspaceOperationsConstants::INTERNAL_BLOCKING_COMMAND_LABEL, BmWorkspaceOperationsConstants::INTERNAL_COMMAND_LABEL, BmWorkspaceOperationsConstants::SECRETS_INVENTORY, BmWorkspaceOperationsConstants::VARIABLES_VOLUME_DEFAULT_MODE, BmWorkspaceOperationsConstants::VARIABLES_VOLUME_NAME, BmWorkspaceOperationsConstants::VARIABLES_VOLUME_PATH, BmWorkspaceOperationsConstants::WORKSPACE_DATA_VOLUME_PATH, BmWorkspaceOperationsConstants::WORKSPACE_INVENTORY, BmWorkspaceOperationsConstants::WORKSPACE_LOGS_DIR, BmWorkspaceOperationsConstants::WORKSPACE_RECONCILED_ACTUAL_STATE_FILE_NAME, BmWorkspaceOperationsConstants::WORKSPACE_RECONCILED_ACTUAL_STATE_FILE_PATH, BmWorkspaceOperationsConstants::WORKSPACE_TOOLS_IMAGE
Constants included from BmFiles
BmFiles::CONTAINER_KEEPALIVE_COMMAND_ARGS, BmFiles::DEFAULT_DEVFILE_YAML, BmFiles::GIT_CREDENTIAL_STORE_SCRIPT, BmFiles::INTERNAL_POSTSTART_COMMAND_CLONE_PROJECT_SCRIPT, BmFiles::INTERNAL_POSTSTART_COMMAND_CLONE_UNSHALLOW_SCRIPT, BmFiles::INTERNAL_POSTSTART_COMMAND_SLEEP_UNTIL_WORKSPACE_IS_RUNNING_SCRIPT, BmFiles::INTERNAL_POSTSTART_COMMAND_START_SSHD_SCRIPT, BmFiles::INTERNAL_POSTSTART_COMMAND_START_VSCODE_SCRIPT, BmFiles::KUBERNETES_LEGACY_POSTSTART_HOOK_COMMAND, BmFiles::KUBERNETES_POSTSTART_HOOK_COMMAND
Class Method Summary collapse
Methods included from BmFiles
container_keepalive_command_args, default_devfile_yaml, git_credential_store_script, internal_poststart_command_clone_project_script, internal_poststart_command_clone_unshallow_script, internal_poststart_command_sleep_until_workspace_is_running_script, internal_poststart_command_start_sshd_script, internal_poststart_command_start_vscode_script, kubernetes_legacy_poststart_hook_command, kubernetes_poststart_hook_command, reload_constants!
Class Method Details
.insert(containers:, devfile_commands:, devfile_events:) ⇒ void
This method returns an undefined value.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/gitlab/background_migration/remote_development/workspace_operations/create/desired_config/bm_kubernetes_poststart_hook_inserter.rb', line 20 def self.insert(containers:, devfile_commands:, devfile_events:) # rubocop:disable Metrics/MethodLength -- copied from ee/lib/remote_development internal_blocking_command_label_present = devfile_commands.any? do |command| command.dig(:exec, :label) == INTERNAL_BLOCKING_COMMAND_LABEL end devfile_events => { postStart: Array => poststart_command_ids } containers_with_devfile_poststart_commands = poststart_command_ids.each_with_object([]) do |poststart_command_id, accumulator| command = devfile_commands.find { |command| command.fetch(:id) == poststart_command_id } command => { exec: { component: String => container_name } } accumulator << container_name end.uniq containers.each do |container| # rubocop:disable Metrics/BlockLength -- need it big container_name = container.fetch(:name) next unless containers_with_devfile_poststart_commands.include?(container_name) if internal_blocking_command_label_present kubernetes_poststart_hook_script = format( KUBERNETES_POSTSTART_HOOK_COMMAND, run_internal_blocking_poststart_commands_script_file_path: "#{WORKSPACE_SCRIPTS_VOLUME_PATH}/#{RUN_INTERNAL_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME}", run_non_blocking_poststart_commands_script_file_path: "#{WORKSPACE_SCRIPTS_VOLUME_PATH}/#{RUN_NON_BLOCKING_POSTSTART_COMMANDS_SCRIPT_NAME}" ) else kubernetes_poststart_hook_script = format( KUBERNETES_LEGACY_POSTSTART_HOOK_COMMAND, run_internal_blocking_poststart_commands_script_file_path: "#{WORKSPACE_SCRIPTS_VOLUME_PATH}/#{LEGACY_RUN_POSTSTART_COMMANDS_SCRIPT_NAME}" ) end container[:lifecycle] = { postStart: { exec: { command: ["/bin/sh", "-c", kubernetes_poststart_hook_script] } } } end nil end |