Skip to content

Add k8s.exec operation for executing commands in containers #8

Description

@Cali0707

Description

Add a k8s.exec operation to execute commands inside running containers. This is critical for functional verification testing in tasks like multi-container-pod-communication, statefulset-lifecycle, and setup-dev-cluster.

Current bash tasks use patterns like:

  • kubectl exec pod-name -c container -- curl -s localhost:80
  • kubectl exec pod-name -n namespace -- cat /data/test
  • kubectl exec pod-name -- nslookup kubernetes.default
  • kubectl exec pod-name -c logger -- ls -la /var/log/nginx/

Requirements

  • Support executing arbitrary commands in a pod's container
  • Support specifying target container in multi-container pods
  • Support namespace specification
  • Capture stdout/stderr and exit code
  • Support an expect block for inline verification of output

Example Usage

Check HTTP response:

- k8s.exec:
    pod: communication-pod
    namespace: multi-container-logging
    container: web-server
    command: ["curl", "-s", "-o", "/dev/null", "-w", "%{http_code}", "localhost:80"]
    expect:
      stdout:
        match: "200"

Verify file contents:

- k8s.exec:
    pod: db-0
    namespace: statefulset-test
    command: ["cat", "/data/test"]
    expect:
      stdout:
        equals: "initial_data"

Acceptance Criteria

  • Can execute a command in a pod by name and namespace
  • Can target a specific container using container name
  • Defaults to first container when container not specified
  • Supports expect.stdout for output assertions (equals, match, contains)
  • Supports expect.exitCode for exit code verification
  • Handles pod not found / container not found errors
  • Operation is documented in extension manifest

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions