Skip to content

Fix error when unmarshaling string with windows path for powershell and pwsh

Romuald Atchadé requested to merge k8s-trap-command-unmarshaling into main

What does this MR do?

Improve the way windows path are handled when unmarshaling trap command for the k8s executor

It also reverts previous logic to get the command path. The previous logic used was missing the fact that pwsh when used with the windows OS could produce the behaviour fixed with powershell

Why was this MR needed?

Make pwsh usable on windows

What's the best way to test this MR?

pwsh on linux system

gitlab-ci
stages:          # List of stages for jobs, and their order of execution
  - build

build-job-161:       # This job runs in the build stage, which runs first.
  stage: build
  image: mcr.microsoft.com/powershell:lts-7.2-alpine-3.16
  script:
    - $PSVersionTable.PSVersion
    - pwsh -Version
    - Start-Sleep -Seconds 120
config.toml
concurrent = 1
check_interval = 1
log_level = "debug"
shutdown_timeout = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = ""
  url = "https://gitlab.com/"
  id = 0
  token = "__REDACTED__"
  token_obtained_at = 0001-01-01T00:00:00Z
  token_expires_at = 0001-01-01T00:00:00Z
  executor = "kubernetes"
  environment = ["FF_USE_POWERSHELL_PATH_RESOLVER=true"]
  shell = "pwsh"
  [runners.kubernetes]
    host = ""
    bearer_token_overwrite_allowed = false
    namespace = ""
    namespace_overwrite_allowed = ""
    node_selector_overwrite_allowed = ""
    poll_timeout = 3600
    pod_labels_overwrite_allowed = ""
    service_account_overwrite_allowed = ""
    pod_annotations_overwrite_allowed = ""


    memory_limit = "8Gi"
    #helper_memory_request = "6Gi"

    [runners.kubernetes.pod_security_context]
    [runners.kubernetes.volumes]
    [runners.kubernetes.dns_config]

Job succeeds

pwsh on windows system

gitlab-ci
stages:          # List of stages for jobs, and their order of execution
  - build

build-job-161:       # This job runs in the build stage, which runs first.
  stage: build
  image: mcr.microsoft.com/powershell:lts-7.2-windowsservercore-ltsc2022
  script:
    - $PSVersionTable.PSVersion
    - pwsh -Version
    - Start-Sleep -Seconds 120
config.toml
concurrent = 1
check_interval = 1
log_level = "debug"
shutdown_timeout = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = ""
  url = "https://gitlab.com/"
  id = 0
  token = "__REDACTED__"
  token_obtained_at = 0001-01-01T00:00:00Z
  token_expires_at = 0001-01-01T00:00:00Z
  executor = "kubernetes"
  environment = ["FF_USE_POWERSHELL_PATH_RESOLVER=true"]
  shell = "pwsh"
  [runners.kubernetes]
    host = ""
    bearer_token_overwrite_allowed = false
    namespace = ""
    namespace_overwrite_allowed = ""
    node_selector_overwrite_allowed = ""
    poll_timeout = 3600
    pod_labels_overwrite_allowed = ""
    service_account_overwrite_allowed = ""
    pod_annotations_overwrite_allowed = ""


    memory_limit = "8Gi"
    #helper_memory_request = "6Gi"

    [runners.kubernetes.node_selector]
      "kubernetes.io/arch" = "amd64"
      "kubernetes.io/os" = "windows"
      "node.kubernetes.io/windows-build" = "10.0.20348"
    [runners.kubernetes.pod_security_context]
    [runners.kubernetes.volumes]
    [runners.kubernetes.dns_config]

Job succeeds

powershell

gitlab-ci
stages:          # List of stages for jobs, and their order of execution
  - build

build-job-161:       # This job runs in the build stage, which runs first.
  stage: build
  image: mcr.microsoft.com/powershell:lts-7.2-windowsservercore-ltsc2022
  script:
    - $PSVersionTable.PSVersion
    - pwsh -Version
    - Start-Sleep -Seconds 120
config.toml
concurrent = 1
check_interval = 1
log_level = "debug"
shutdown_timeout = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = ""
  url = "https://gitlab.com/"
  id = 0
  token = "__REDACTED__"
  token_obtained_at = 0001-01-01T00:00:00Z
  token_expires_at = 0001-01-01T00:00:00Z
  executor = "kubernetes"
  environment = ["FF_USE_POWERSHELL_PATH_RESOLVER=true"]
  shell = "powershell"
  [runners.kubernetes]
    host = ""
    bearer_token_overwrite_allowed = false
    namespace = ""
    namespace_overwrite_allowed = ""
    node_selector_overwrite_allowed = ""
    poll_timeout = 3600
    pod_labels_overwrite_allowed = ""
    service_account_overwrite_allowed = ""
    pod_annotations_overwrite_allowed = ""


    memory_limit = "8Gi"
    #helper_memory_request = "6Gi"

    [runners.kubernetes.node_selector]
      "kubernetes.io/arch" = "amd64"
      "kubernetes.io/os" = "windows"
      "node.kubernetes.io/windows-build" = "10.0.20348"
    [runners.kubernetes.pod_security_context]
    [runners.kubernetes.volumes]
    [runners.kubernetes.dns_config]

Job succeeds

If you are using GKE

  • Create a cluster on GKE
  • Add a node pool which supports ltsc2019 (see command below)
gcloud container node-pools create NODE_POOL \ 
    --cluster=CLUSTER_NAME --region=REGION \
    --image-type=WINDOWS_LTSC_CONTAINERD \
    --no-enable-autoupgrade \
    --machine-type=MACHINE_TYPE --num-nodes=1 \
    --windows-os-version=ltsc2019
  • Add a node pool which supports ltsc2022 (see command below)
gcloud container node-pools create NODE_POOL \ 
    --cluster=CLUSTER_NAME --region=REGION \
    --image-type=WINDOWS_LTSC_CONTAINERD \
    --no-enable-autoupgrade \
    --machine-type=MACHINE_TYPE --num-nodes=1 \
    --windows-os-version=ltsc2022

What are the relevant issue numbers?

fixes https://gitlab.com/gitlab-com/ops-sub-department/section-ops-request-for-help/-/issues/173

Edited by Romuald Atchadé

Merge request reports