Skip to content

Commit

Permalink
Add basic e2e test for kubectl plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
chiayi committed Aug 7, 2024
1 parent dea87ff commit 301b5d5
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 19 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/e2e-tests-reusable-workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: e2e test reusable workflow setup

on:
workflow_call:
input:
TEMP_DIR:
required: true
secrets:
GITHUB_TOKEN:
required: true

jobs:
build:
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
submodules: recursive

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: v1.22

- name: Set up gotestfmt
uses: gotesttools/gotestfmt-action@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Setup and start KinD cluster
uses: ./.github/workflows/actions/kind

- name: Deploy Kuberay operator
id: deploy
run: |
echo Deploying Kuberay operator
cd ray-operator
IMG="${REGISTRY_ADDRESS}"/kuberay
make docker-build -e IMG="${IMG}" -e ENGINE=podman
make docker-push -e IMG="${IMG}" -e ENGINE=podman
make deploy -e IMG="${IMG}"
kubectl wait --timeout=90s --for=condition=Available=true deployment -n ray-system kuberay-operator
- name: Run e2e tests
run: |
export KUBERAY_TEST_TIMEOUT_SHORT=1m
export KUBERAY_TEST_TIMEOUT_MEDIUM=5m
export KUBERAY_TEST_TIMEOUT_LONG=10m
export KUBERAY_TEST_OUTPUT_DIR=${{ input.TEMP_DIR }}
echo "KUBERAY_TEST_OUTPUT_DIR=${KUBERAY_TEST_OUTPUT_DIR}" >> GITHUB_ENV
set -euo pipefail
cd ray-operator
go test -timeout 30m -v ./test/e2e -json 2>&1 | tee ${KUBERAY_TEST_OUTPUT_DIR}/gotest.log | gotestfmt
- name: Print KubeRay operator logs
if: always() && steps.deploy.outcome == 'success'
run: |
echo "Printing KubeRay operator logs"
kubectl logs -n ray-system --tail -1 -l app.kubernetes.io/name=kuberay | tee ${KUBERAY_TEST_OUTPUT_DIR}/kuberay-operator.log
- name: Upload logs
uses: actions/upload-artifact@v3
if: always() && steps.deploy.outcome == 'success'
with:
name: logs
retention-days: 10
path: |
${{ env.KUBERAY_TEST_OUTPUT_DIR }}/**/*.log
39 changes: 21 additions & 18 deletions .github/workflows/e2e-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ concurrency:

jobs:
ray-operator:

setup_ray_operator_e2e_test:
uses: ./.github/workflows/e2e-tests-workflow.yaml
with:
TEMP_DIR: ${{ env.TEMP_DIR }}
secrets:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

ray-kubectl-plugin:
runs-on: ubuntu-20.04

steps:
- name: Checkout code
uses: actions/checkout@v3
Expand All @@ -50,6 +56,15 @@ jobs:
- name: Setup and start KinD cluster
uses: ./.github/workflows/actions/kind

- name: Build CLI and Add to PATH
run: |
cd ./kubectl-plugin
go mod download
go build -o kubectl-ray -a ./cmd/kubectl-ray.go
cp ./kubectl-ray /usr/local/bin
- name: Deploy Kuberay operator
id: deploy
run: |
Expand All @@ -63,6 +78,9 @@ jobs:
make deploy -e IMG="${IMG}"
kubectl wait --timeout=90s --for=condition=Available=true deployment -n ray-system kuberay-operator
kubectl apply -f ../ray-operator/config/samples/ray-cluster.sample.yaml
kubectl wait --timeout=90s --for=condition=Available=true deployment raycluster
- name: Run e2e tests
run: |
export KUBERAY_TEST_TIMEOUT_SHORT=1m
Expand All @@ -73,20 +91,5 @@ jobs:
echo "KUBERAY_TEST_OUTPUT_DIR=${KUBERAY_TEST_OUTPUT_DIR}" >> $GITHUB_ENV
set -euo pipefail
cd ray-operator
cd kubectl-plugin
go test -timeout 30m -v ./test/e2e -json 2>&1 | tee ${KUBERAY_TEST_OUTPUT_DIR}/gotest.log | gotestfmt
- name: Print KubeRay operator logs
if: always() && steps.deploy.outcome == 'success'
run: |
echo "Printing KubeRay operator logs"
kubectl logs -n ray-system --tail -1 -l app.kubernetes.io/name=kuberay | tee ${KUBERAY_TEST_OUTPUT_DIR}/kuberay-operator.log
- name: Upload logs
uses: actions/upload-artifact@v3
if: always() && steps.deploy.outcome == 'success'
with:
name: logs
retention-days: 10
path: |
${{ env.KUBERAY_TEST_OUTPUT_DIR }}/**/*.log
2 changes: 1 addition & 1 deletion kubectl-plugin/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
k8s.io/api v0.30.2
k8s.io/apimachinery v0.30.2
k8s.io/cli-runtime v0.30.2
k8s.io/client-go v0.30.2
Expand Down Expand Up @@ -80,7 +81,6 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.30.2 // indirect
k8s.io/component-base v0.30.2 // indirect
k8s.io/klog/v2 v2.120.1 // indirect
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
Expand Down
39 changes: 39 additions & 0 deletions kubectl-plugin/test/e2e/kubectl_ray_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package e2e

import (
"os/exec"
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestKubectlRayGet(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Kubectl Ray Get")
}

var _ = Describe("Calling ray plugin `get` command", Ordered, func() {
It("succeed in getting ray cluster information", func() {
cmd := exec.Command("kubectl", "ray", "cluster", "get")
output, err := cmd.CombinedOutput()

Expect(err).NotTo(HaveOccurred())
Expect(output).To(ContainSubstring("raycluster-sample"))
})

It("should not succeed", func() {
cmd := exec.Command("kubectl", "ray", "cluster", "get", "fakeclustername", "anotherfakeclustername")
output, err := cmd.CombinedOutput()

Expect(err).To(HaveOccurred())
Expect(output).ToNot(ContainElements("fakeclustername"))
})

It("will have a `namespace` and should succeed without error", func() {
cmd := exec.Command("kubectl", "ray", "cluster", "get", "--namespace", "default")
output, err := cmd.CombinedOutput()

Expect(err).NotTo(HaveOccurred(), "%s: %s", err, output)
})
})

0 comments on commit 301b5d5

Please sign in to comment.