actions / runner-container-hooks

Runner Container Hooks for GitHub Actions
MIT License
73 stars 44 forks source link

bug: K8s Prepare job webhook fails to create a pod for two services that use the same image #139

Open DenisPalnitsky opened 7 months ago

DenisPalnitsky commented 7 months ago

Prerequisites

Have Actions Runners Controller with AutoscalingRunnerSet configured in Kubernetes mode

Steps to reproduce

  1. Create workflow
    
    name: CI
    on:  
    push:   
    workflow_dispatch:

jobs: build:
container: image: ghcr.io/actions/actions-runner:latest

services:
  redis:
    image: redis:6.2.5

  redis01:
      image: redis:6.2.5

runs-on: [MY_ACTIONS_RUNNERSET_NAME]
steps:
  - run: echo "Hello, world!"
    name: echo
Note that we want to use two redis service one with `redis` and other `redis01` and that's how we want to reach them from workflow.

2. Run workflow

## Expected Result
Workflow executed.

## Actual result
Workflow fails on  `Initialise containers` step  with error 

[debug]Evaluating condition for step: 'Initialize containers'

[debug]Evaluating: success()

[debug]Evaluating success:

[debug]=> true

[debug]Result: true

[debug]Starting: Initialize containers

[debug]Register post job cleanup for stopping/deleting containers.

Run '/home/runner/k8s/index.js' shell: /home/runner/externals/node16/bin/node {0}

[debug]/home/runner/externals/node16/bin/node /home/runner/k8s/index.js

[debug]Using image 'ghcr.io/actions/actions-runner:latest' for job image

[debug]Adding service 'redis:6.2.5' to pod definition

[debug]Adding service 'redis:6.2.5' to pod definition

Error: Error: failed to create job pod: HttpError: HTTP request failed Error: Process completed with exit code 1. Error: Executing the custom container implementation failed. Please contact your self hosted runner administrator.

[debug]System.Exception: Executing the custom container implementation failed. Please contact your self hosted runner administrator.

[debug] ---> System.Exception: The hook script at '/home/runner/k8s/index.js' running command 'PrepareJob' did not execute successfully

[debug] at GitHub.Runner.Worker.Container.ContainerHooks.ContainerHookManager.ExecuteHookScript[T](IExecutionContext context, HookInput input, ActionRunStage stage, String prependPath)

[debug] --- End of inner exception stack trace ---

[debug] at GitHub.Runner.Worker.Container.ContainerHooks.ContainerHookManager.ExecuteHookScript[T](IExecutionContext context, HookInput input, ActionRunStage stage, String prependPath)

[debug] at GitHub.Runner.Worker.Container.ContainerHooks.ContainerHookManager.PrepareJobAsync(IExecutionContext context, List`1 containers)

[debug] at GitHub.Runner.Worker.ContainerOperationProvider.StartContainersAsync(IExecutionContext executionContext, Object data)

[debug] at GitHub.Runner.Worker.JobExtensionRunner.RunAsync()

[debug] at GitHub.Runner.Worker.StepsRunner.RunStepAsync(IStep step, CancellationToken jobCancellationToken)

[debug]Finishing: Initialize containers

DenisPalnitsky commented 7 months ago

I checked the args that prepareJob function receives and it does not have unique 'name'

  "services": [
        {
            "image": "redis:6.2.5",
            "dockerfile": null,
            "entryPointArgs": [],
            "entryPoint": null,
            "workingDirectory": null,
            "createOptions": null,
            "registry": null,
            "environmentVariables": {},
            "portMappings": [],
            "systemMountVolumes": [],
            "userMountVolumes": []
        },
        {
            "image": "redis:6.2.5",
            "dockerfile": null,
            "entryPointArgs": [],
            "entryPoint": null,
            "workingDirectory": null,
            "createOptions": null,
            "registry": null,
            "environmentVariables": {},
            "portMappings": [],
            "systemMountVolumes": [],
            "userMountVolumes": []
        }
    ]

I guess we need to add names to that code that passes those args first.