gruntwork-io / terratest

Terratest is a Go library that makes it easier to write automated tests for your infrastructure code.
https://terratest.gruntwork.io/
Apache License 2.0
7.39k stars 1.32k forks source link

executable file not found in $PATH #1403

Open JCzz opened 2 months ago

JCzz commented 2 months ago

Describe the bug I was expecting terratest to use client-go, when run in container within a container?

To Reproduce Create a Dockerfile:

# syntax=docker/dockerfile:1

FROM golang:1.21.7 AS builder
ARG TEST_FOLDER

WORKDIR /app

COPY go.mod go.sum ./
RUN go mod download

COPY $TEST_FOLDER/*.go ./
COPY $TEST_FOLDER/*.yml ./

Build using:

TEST_FOLDER=./kubernetes-hello-world-example
DOCKERFILE=./Dockerfile
docker build --build-arg="TEST_FOLDER=$TEST_FOLDER" --target builder -t terratest:latest -q -f Dockerfile .

Pod:

apiVersion: v1
kind: Pod
metadata:
  name: command-demo
  labels:
    purpose: demonstrate-command
spec:
  containers:
  - name: command-demo-container
    image: docker.io/library/terratest:latest
    imagePullPolicy: Never
    command: ["go"]
    args: ["test", "kubernetes_hello_world_example_test.go"]
  restartPolicy: OnFailure

Error:

kubernetes_hello_world_example_test.go:25
                Error:          Received unexpected error:
                                error while running command: exec: "kubectl": executable file not found in $PATH; 

Expected behavior A clear and concise description of what you expected to happen.

Nice to have

Versions

Additional context Add any other context about the problem here.

denis256 commented 2 months ago

Hi, yes kubectl is required to be in path, AFAIK it is to be able to re-use existing configurations through KUBECONFIG and to be able to use kustomize through kubectl apply -k