diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index f605e90b2d..3261b542a8 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -32,96 +32,96 @@ jobs: make version echo "::set-output name=product-version::$(make version)" -# build-distros: -# needs: [get-go-version, get-product-version] -# runs-on: ubuntu-latest -# strategy: -# matrix: -# include: -# # cli -# - {go: "${{ needs.get-go-version.outputs.go-version }}", goos: "linux", goarch: "amd64", component: "cli", pkg_name: "consul-k8s", "bin_name": "consul-k8s" } -# # control-plane -# - {go: "${{ needs.get-go-version.outputs.go-version }}", goos: "linux", goarch: "amd64", component: "control-plane", pkg_name: "consul-k8s-control-plane", "bin_name": "consul-k8s-control-plane" } -# # consul-cni -# - {go: "${{ needs.get-go-version.outputs.go-version }}", goos: "linux", goarch: "amd64", component: "control-plane/cni", pkg_name: "consul-cni", "bin_name": "consul-cni" } -# -# fail-fast: true -# -# name: Go ${{ matrix.go }} ${{ matrix.goos }} ${{ matrix.goarch }} ${{ matrix.component }} build -# steps: -# - uses: actions/checkout@v3 -# -# - name: Setup go -# uses: actions/setup-go@v3 -# with: -# go-version: ${{ matrix.go }} -# -# - name: Build -# env: -# GOOS: ${{ matrix.goos }} -# GOARCH: ${{ matrix.goarch }} -# CGO_ENABLED: 0 -# working-directory: ${{ matrix.component }} -# run: | -# mkdir -p dist out -# -# export GIT_COMMIT=$(git rev-parse --short HEAD) -# export GIT_DIRTY=$(test -n "$(git status --porcelain)" && echo "+CHANGES") -# export GIT_IMPORT=github.com/hashicorp/consul-k8s/${{ matrix.component }}/version -# export GOLDFLAGS="-X ${GIT_IMPORT}.GitCommit=${GIT_COMMIT}${GIT_DIRTY} -X ${GIT_IMPORT}.GitDescribe=${{ needs.get-product-version.outputs.product-version }}" -# -# CGO_ENABLED=0 go build -o dist/${{ matrix.bin_name }} -ldflags "${GOLDFLAGS}" . -# zip -r -j out/${{ matrix.pkg_name }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip dist/ -# -# - name: Upload built binaries -# uses: actions/upload-artifact@v3 -# with: -# name: ${{ matrix.pkg_name }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip -# path: ${{ matrix.component}}/out/${{ matrix.pkg_name }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip -# -# dev-upload-docker: -# if: github.repository_owner == 'hashicorp' # Do not run on forks as this requires secrets -# needs: [ get-product-version, build-distros ] -# runs-on: ubuntu-latest -# strategy: -# matrix: -# arch: [ "amd64" ] -# env: -# repo: ${{ github.event.repository.name }} -# version: ${{ needs.get-product-version.outputs.product-version }} -# steps: -# - uses: actions/checkout@v3 -# - uses: actions/download-artifact@v3 -# with: -# name: consul-cni_${{ needs.get-product-version.outputs.product-version }}_linux_${{ matrix.arch }}.zip -# path: control-plane/dist/cni/linux/${{ matrix.arch }} -# - name: extract consul-cni zip -# env: -# ZIP_LOCATION: control-plane/dist/cni/linux/${{ matrix.arch }} -# run: | -# cd "${ZIP_LOCATION}" -# unzip -j *.zip -# - name: Docker Build (Action) -# uses: hashicorp/actions-docker-build@v1 -# with: -# smoke_test: | -# TEST_VERSION="$(docker run "${IMAGE_NAME}" consul-k8s-control-plane version | awk '{print $2}')" -# if [ "${TEST_VERSION}" != "v${version}" ]; then -# echo "Test FAILED" -# exit 1 -# fi -# echo "Test PASSED" -# version: ${{ env.version }} -# target: release-default -# arch: ${{ matrix.arch }} -# pkg_name: consul-k8s-control-plane_${{ env.version }} -# bin_name: consul-k8s-control-plane -# workdir: control-plane -# tags: | -# docker.io/hashicorp/${{ env.repo }}-control-plane:${{ env.version }} -# dev_tags: | -# hashicorppreview/${{ env.repo }}-control-plane:${{ env.version }} -# docker.io/hashicorppreview/${{ env.repo }}-control-plane:${{ env.version }}-${{ github.sha }} + build-distros: + needs: [get-go-version, get-product-version] + runs-on: ubuntu-latest + strategy: + matrix: + include: + # cli + - {go: "${{ needs.get-go-version.outputs.go-version }}", goos: "linux", goarch: "amd64", component: "cli", pkg_name: "consul-k8s", "bin_name": "consul-k8s" } + # control-plane + - {go: "${{ needs.get-go-version.outputs.go-version }}", goos: "linux", goarch: "amd64", component: "control-plane", pkg_name: "consul-k8s-control-plane", "bin_name": "consul-k8s-control-plane" } + # consul-cni + - {go: "${{ needs.get-go-version.outputs.go-version }}", goos: "linux", goarch: "amd64", component: "control-plane/cni", pkg_name: "consul-cni", "bin_name": "consul-cni" } + + fail-fast: true + + name: Go ${{ matrix.go }} ${{ matrix.goos }} ${{ matrix.goarch }} ${{ matrix.component }} build + steps: + - uses: actions/checkout@v3 + + - name: Setup go + uses: actions/setup-go@v3 + with: + go-version: ${{ matrix.go }} + + - name: Build + env: + GOOS: ${{ matrix.goos }} + GOARCH: ${{ matrix.goarch }} + CGO_ENABLED: 0 + working-directory: ${{ matrix.component }} + run: | + mkdir -p dist out + + export GIT_COMMIT=$(git rev-parse --short HEAD) + export GIT_DIRTY=$(test -n "$(git status --porcelain)" && echo "+CHANGES") + export GIT_IMPORT=github.com/hashicorp/consul-k8s/${{ matrix.component }}/version + export GOLDFLAGS="-X ${GIT_IMPORT}.GitCommit=${GIT_COMMIT}${GIT_DIRTY} -X ${GIT_IMPORT}.GitDescribe=${{ needs.get-product-version.outputs.product-version }}" + + CGO_ENABLED=0 go build -o dist/${{ matrix.bin_name }} -ldflags "${GOLDFLAGS}" . + zip -r -j out/${{ matrix.pkg_name }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip dist/ + + - name: Upload built binaries + uses: actions/upload-artifact@v3 + with: + name: ${{ matrix.pkg_name }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip + path: ${{ matrix.component}}/out/${{ matrix.pkg_name }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip + + dev-upload-docker: + if: github.repository_owner == 'hashicorp' # Do not run on forks as this requires secrets + needs: [ get-product-version, build-distros ] + runs-on: ubuntu-latest + strategy: + matrix: + arch: [ "amd64" ] + env: + repo: ${{ github.event.repository.name }} + version: ${{ needs.get-product-version.outputs.product-version }} + steps: + - uses: actions/checkout@v3 + - uses: actions/download-artifact@v3 + with: + name: consul-cni_${{ needs.get-product-version.outputs.product-version }}_linux_${{ matrix.arch }}.zip + path: control-plane/dist/cni/linux/${{ matrix.arch }} + - name: extract consul-cni zip + env: + ZIP_LOCATION: control-plane/dist/cni/linux/${{ matrix.arch }} + run: | + cd "${ZIP_LOCATION}" + unzip -j *.zip + - name: Docker Build (Action) + uses: hashicorp/actions-docker-build@v1 + with: + smoke_test: | + TEST_VERSION="$(docker run "${IMAGE_NAME}" consul-k8s-control-plane version | awk '{print $2}')" + if [ "${TEST_VERSION}" != "v${version}" ]; then + echo "Test FAILED" + exit 1 + fi + echo "Test PASSED" + version: ${{ env.version }} + target: release-default + arch: ${{ matrix.arch }} + pkg_name: consul-k8s-control-plane_${{ env.version }} + bin_name: consul-k8s-control-plane + workdir: control-plane + tags: | + docker.io/hashicorp/${{ env.repo }}-control-plane:${{ env.version }} + dev_tags: | + hashicorppreview/${{ env.repo }}-control-plane:${{ env.version }} + docker.io/hashicorppreview/${{ env.repo }}-control-plane:${{ env.version }}-${{ github.sha }} acceptance: # needs: dev-upload-docker diff --git a/.github/workflows/reusable-acceptance.yml b/.github/workflows/reusable-acceptance.yml index 2d9090a726..243fdccad7 100644 --- a/.github/workflows/reusable-acceptance.yml +++ b/.github/workflows/reusable-acceptance.yml @@ -41,14 +41,14 @@ jobs: runs-on: [custom, linux, xl] strategy: matrix: - include: # I am really sorry for this but I could not find a way to automatically split our tests into several runners. For now, split manually. - #- {runner: "0", test-packages: "basic consul-dns"} + include: + - {runner: "0", test-packages: "basic consul-dns"} - {runner: "1", test-packages: "connect"} - #- {runner: "2", test-packages: "controller example"} - #- {runner: "3", test-packages: "ingress-gateway"} - #- {runner: "4", test-packages: "metrics partitions"} - #- {runner: "5", test-packages: "peering"} - #- {runner: "6", test-packages: "snapshot-agent sync terminating-gateway vault wan-federation"} + - {runner: "2", test-packages: "controller example"} + - {runner: "3", test-packages: "ingress-gateway"} + - {runner: "4", test-packages: "metrics partitions"} + - {runner: "5", test-packages: "peering"} + - {runner: "6", test-packages: "snapshot-agent sync terminating-gateway vault wan-federation"} fail-fast: false steps: @@ -104,9 +104,8 @@ jobs: kind create cluster --name dc1 --image kindest/node:${{ inputs.kind-version }} kind create cluster --name dc2 --image kindest/node:${{ inputs.kind-version }} - - name: Build binaries + - name: Build CLI run: | - ls sudo make cli-dev # We have to run the tests for each package separately so that we can @@ -123,7 +122,11 @@ jobs: fullpkg="github.com/hashicorp/consul-k8s/${{ inputs.directory }}/${pkg}" echo "Testing package: ${fullpkg}" if ! gotestsum --jsonfile=jsonfile-${pkg////-} -- ${fullpkg} -p 1 -timeout 2h -failfast \ - -run=TestConnectInject/"CLI install without secure" -v + ${{ inputs.additional-flags }} \ + -enable-enterprise \ + -enable-multi-cluster \ + -debug-directory=${{ env.TEST_RESULTS }}/debug \ + -consul-k8s-image=${{ inputs.consul-k8s-image }} then echo "Tests in ${pkg} failed, aborting early" exit_code=1 diff --git a/acceptance/framework/cli/cli.go b/acceptance/framework/cli/cli.go index 66fb48ab2d..c75297425f 100644 --- a/acceptance/framework/cli/cli.go +++ b/acceptance/framework/cli/cli.go @@ -2,7 +2,9 @@ package cli import ( "fmt" + "os" "os/exec" + "path/filepath" "strings" "testing" @@ -10,6 +12,10 @@ import ( "github.com/hashicorp/consul-k8s/acceptance/framework/logger" ) +const ( + cliBinaryName = "consul-k8s" +) + // CLI provides access to compile and execute commands with the `consul-k8s` CLI. type CLI struct { initialized bool @@ -18,6 +24,10 @@ type CLI struct { // NewCLI compiles the `consul-k8s` CLI and returns a handle to execute commands // with the binary. func NewCLI() (*CLI, error) { + _, err := os.Stat(filepath.Join(os.Getenv("GOPATH"), "bin", "consul-k8s")) + if err != nil { + return nil, err + } return &CLI{true}, nil } @@ -36,6 +46,6 @@ func (c *CLI) Run(t *testing.T, options *k8s.KubectlOptions, args ...string) ([] } logger.Logf(t, "Running `consul-k8s %s`", strings.Join(args, " ")) - cmd := exec.Command("consul-k8s", args...) + cmd := exec.Command(cliBinaryName, args...) return cmd.Output() } diff --git a/acceptance/framework/config/config.go b/acceptance/framework/config/config.go index 7bcb1725a5..ad10845ba0 100644 --- a/acceptance/framework/config/config.go +++ b/acceptance/framework/config/config.go @@ -15,7 +15,6 @@ import ( // Note: this will need to be changed if this file is moved. const ( HelmChartPath = "../../../charts/consul" - CLIPath = "../../../cli" LicenseSecretName = "license" LicenseSecretKey = "key" )