diff --git a/.github/workflows/kind.yml b/.github/workflows/kind.yml index 253bcceebaf..bd01f15d644 100644 --- a/.github/workflows/kind.yml +++ b/.github/workflows/kind.yml @@ -741,8 +741,8 @@ jobs: path: log.tar.gz retention-days: 30 - run-post-installation-checks: - name: Test connectivity using 'antctl check' command + run-installation-checks: + name: Test installation using 'antctl check' command needs: [ build-antrea-coverage-image ] runs-on: [ ubuntu-latest ] steps: @@ -772,13 +772,16 @@ jobs: - name: Create Kind Cluster run: | ./ci/kind/kind-setup.sh create kind --ip-family dual - - name: Deploy Antrea - run: | - kubectl apply -f build/yamls/antrea.yml - name: Build antctl binary run: | make antctl-linux - - name: Run antctl command + - name: Run Pre checks + run: | + /bin/antctl-linux check cluster + - name: Deploy Antrea + run: | + kubectl apply -f build/yamls/antrea.yml + - name: Run Post checks run: | ./bin/antctl-linux check installation diff --git a/pkg/antctl/raw/check/cluster/command.go b/pkg/antctl/raw/check/cluster/command.go index e297f06f0ba..a18a89cef09 100644 --- a/pkg/antctl/raw/check/cluster/command.go +++ b/pkg/antctl/raw/check/cluster/command.go @@ -20,6 +20,7 @@ import ( "os" "time" + "github.com/fatih/color" "github.com/spf13/cobra" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -88,16 +89,22 @@ func Run(o *options) error { if err := testContext.setup(ctx); err != nil { return err } + var numSuccess, numFailure int for name, test := range testsRegistry { testContext.Header("Running test: %s", name) if err := test.Run(ctx, testContext); err != nil { - testContext.Header("Test %s failed: %s", name, err) + testContext.Fail("Test %s failed: %v", name, err) + numFailure++ } else { - testContext.Header("Test %s passed", name) + testContext.Success("Test %s passed", name) + numSuccess++ } } - testContext.Log("Test finished") + testContext.Log("Test finished: %v tests succeeded, %v tests failed ", numSuccess, numFailure) check.Teardown(ctx, testContext.client, testContext.clusterName, testContext.namespace) + if numFailure > 0 { + return fmt.Errorf("%v/%v tests failed", numFailure, len(testsRegistry)) + } return nil } @@ -184,6 +191,18 @@ func (t *testContext) Log(format string, a ...interface{}) { fmt.Fprintf(os.Stdout, fmt.Sprintf("[%s] ", t.clusterName)+format+"\n", a...) } +func (t *testContext) Success(format string, a ...interface{}) { + fmt.Fprintf(os.Stdout, fmt.Sprintf("[%s] ", t.clusterName)+color.GreenString(format, a...)+"\n") +} + +func (t *testContext) Fail(format string, a ...interface{}) { + fmt.Fprintf(os.Stdout, fmt.Sprintf("[%s] ", t.clusterName)+color.RedString(format, a...)+"\n") +} + +func (t *testContext) Warning(format string, a ...interface{}) { + fmt.Fprintf(os.Stdout, fmt.Sprintf("[%s] ", t.clusterName)+color.YellowString(format, a...)+"\n") +} + func (t *testContext) Header(format string, a ...interface{}) { t.Log("-------------------------------------------------------------------------------------------") t.Log(format, a...)