From bf3a3a2d28f8ce7f1b7ed7252f4b3a7dd0811e72 Mon Sep 17 00:00:00 2001 From: Michael Wilkerson Date: Fri, 21 Oct 2022 09:21:46 -0700 Subject: [PATCH 1/3] removed make target for GitHub, no longer needed --- control-plane/Makefile | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/control-plane/Makefile b/control-plane/Makefile index 7dd5ef80d3..4c3cbac971 100644 --- a/control-plane/Makefile +++ b/control-plane/Makefile @@ -51,24 +51,4 @@ ifeq ($(CIRCLE_BRANCH), main) @echo "Pushed dev image to: $(CI_DEV_DOCKER_NAMESPACE)/$(CI_DEV_DOCKER_IMAGE_NAME):latest" endif -# In Github Actions, the linux binary will be attached from a previous step at pkg/bin/linux_amd64/. This make target -# should only run in CI and not locally. -ci.dev-docker-github: - @echo "Pulling consul-k8s container image - $(CONSUL_K8S_IMAGE_VERSION)" - @docker pull hashicorp/consul-k8s:$(CONSUL_K8S_IMAGE_VERSION) >/dev/null #todo change this back after pulling it the first time since the dockerfile is FROM this image - @echo "Building consul-k8s Development container - $(CI_DEV_DOCKER_IMAGE_NAME)" - @docker build -t '$(CI_DEV_DOCKER_NAMESPACE)/$(CI_DEV_DOCKER_IMAGE_NAME):$(GIT_COMMIT)' \ - --build-arg CONSUL_K8S_IMAGE_VERSION=$(CONSUL_K8S_IMAGE_VERSION) \ - --label COMMIT_SHA=$(GITHUB_SHA) \ - --label PULL_REQUEST=$(GITHIB_PULL_REQUEST) \ - --label GITHUB_BUILD_URL=$(GITHUB_SERVER_URL)/$(GITHUB_REPOSITORY)/actions/runs/$(GITHUB_RUN_ID) \ - $(CI_DEV_DOCKER_WORKDIR) -f $(CURDIR)/build-support/docker/Dev.dockerfile - @echo $(DOCKER_PASS) | docker login -u="$(DOCKER_USER)" --password-stdin - @echo "Pushing dev image to: https://cloud.docker.com/u/$(CI_DEV_DOCKER_NAMESPACE)/repository/docker/$(CI_DEV_DOCKER_NAMESPACE)/$(CI_DEV_DOCKER_IMAGE_NAME)" - @docker push $(CI_DEV_DOCKER_NAMESPACE)/$(CI_DEV_DOCKER_IMAGE_NAME):$(GIT_COMMIT) -ifeq ($(GITHUB_REF_NAME), main) - @docker tag $(CI_DEV_DOCKER_NAMESPACE)/$(CI_DEV_DOCKER_IMAGE_NAME):$(GIT_COMMIT) $(CI_DEV_DOCKER_NAMESPACE)/$(CI_DEV_DOCKER_IMAGE_NAME):latest - @docker push $(CI_DEV_DOCKER_NAMESPACE)/$(CI_DEV_DOCKER_IMAGE_NAME):latest -endif - .PHONY: ci.dev-tree ci.dev-docker ci.dev-docker-github From 3c76327d84889c54da06ede51d061e3baac0a4ca Mon Sep 17 00:00:00 2001 From: Michael Wilkerson Date: Fri, 21 Oct 2022 09:22:38 -0700 Subject: [PATCH 2/3] The name CLI conflicts with the runner - build consul-k8s CLI in pipeline instead for GH action (in future commit) - build consul-K8s CLI in pipeline for CircleCI. CircleCI uses some different go pathing so can't use make cli-dev explicitly for build-cli step - change name of cli binary from cli to consul-k8s --- .circleci/config.yml | 19 +++++++++++++++++-- acceptance/framework/cli/cli.go | 15 +++++++-------- acceptance/framework/config/config.go | 1 - 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 3196ac2e50..d57c6f86d3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -27,7 +27,7 @@ commands: install-prereqs: steps: - run: - name: Install gotestsum, kind, kubectl, and helm + name: Install go, gotestsum, kind, kubectl, and helm command: | wget https://golang.org/dl/go1.18.3.linux-amd64.tar.gz sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.18.3.linux-amd64.tar.gz @@ -71,6 +71,16 @@ commands: make kind-cni-calico kind create cluster --config=acceptance/framework/environment/cni-kind/kind.config --name dc2 --image kindest/node:<< parameters.version >> make kind-cni-calico + build-cli: + steps: + - run: + name: Build consul-k8s CLI + working_directory: *cli-path + command: | + go build -o ./bin/consul-k8s + sudo cp ./bin/consul-k8s /usr/local/go/bin/ + consul-k8s version + run-acceptance-tests: parameters: failfast: @@ -518,6 +528,7 @@ jobs: key: consul-helm-modcache-v2-{{ checksum "acceptance/go.mod" }} paths: - ~/.go_workspace/pkg/mod + - build-cli - run: mkdir -p $TEST_RESULTS - run-acceptance-tests: failfast: true @@ -550,6 +561,7 @@ jobs: key: consul-helm-modcache-v2-{{ checksum "acceptance/go.mod" }} paths: - ~/.go_workspace/pkg/mod + - build-cli - run: mkdir -p $TEST_RESULTS - run-acceptance-tests: failfast: true @@ -582,6 +594,7 @@ jobs: key: consul-helm-modcache-v2-{{ checksum "acceptance/go.mod" }} paths: - ~/.go_workspace/pkg/mod + - build-cli - run: mkdir -p $TEST_RESULTS - run-acceptance-tests: failfast: true @@ -1108,6 +1121,7 @@ jobs: key: consul-helm-modcache-v2-{{ checksum "acceptance/go.mod" }} paths: - ~/.go_workspace/pkg/mod + - build-cli - run: mkdir -p $TEST_RESULTS - run-acceptance-tests: additional-flags: -use-kind -kubecontext="kind-dc1" -secondary-kubecontext="kind-dc2" -enable-transparent-proxy -consul-k8s-image=$CONSUL_K8S_IMAGE -consul-image=$CONSUL_IMAGE -consul-version="1.11" -envoy-image=$ENVOY_IMAGE -helm-chart-version=$HELM_CHART_VERSION @@ -1184,6 +1198,7 @@ jobs: key: consul-helm-modcache-v2-{{ checksum "acceptance/go.mod" }} paths: - ~/.go_workspace/pkg/mod + - build-cli - run: mkdir -p $TEST_RESULTS - run-acceptance-tests: additional-flags: -use-kind -kubecontext="kind-dc1" -secondary-kubecontext="kind-dc2" -enable-transparent-proxy -consul-k8s-image=$CONSUL_K8S_IMAGE -consul-image=$CONSUL_IMAGE -consul-version="1.13" -envoy-image=$ENVOY_IMAGE -helm-chart-version=$HELM_CHART_VERSION @@ -1204,6 +1219,7 @@ workflows: # The rest of these CircleCI jobs have been migrated to Github Actions. We need to wait until # the summer of 2022 for larger puplic Github Action VMs be available before the acceptance tests can # be moved + # Run acceptance tests using the docker image built for the control plane - build-distro: OS: "linux" ARCH: "amd64 arm64" @@ -1212,7 +1228,6 @@ workflows: context: consul-ci requires: - build-distros-linux - # Run acceptance tests using the docker image built for the control plane - acceptance: context: consul-ci requires: diff --git a/acceptance/framework/cli/cli.go b/acceptance/framework/cli/cli.go index 81fe353525..5297382d94 100644 --- a/acceptance/framework/cli/cli.go +++ b/acceptance/framework/cli/cli.go @@ -7,22 +7,21 @@ import ( "testing" "github.com/gruntwork-io/terratest/modules/k8s" - "github.com/hashicorp/consul-k8s/acceptance/framework/config" "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 } -// NewCLI compiles the `consul-k8s` CLI and returns a handle to execute commands -// with the binary. +// NewCLI returns a handle to execute commands with the consul-k8s binary. func NewCLI() (*CLI, error) { - cmd := exec.Command("go", "install", ".") - cmd.Dir = config.CLIPath - _, err := cmd.Output() - return &CLI{true}, err + return &CLI{true}, nil } // Run runs the CLI with the given args. @@ -40,6 +39,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("cli", args...) + cmd := exec.Command(cliBinaryName, args...) return cmd.Output() } diff --git a/acceptance/framework/config/config.go b/acceptance/framework/config/config.go index f0b50358fe..11a04f1622 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" ) From d65312b6e4604faca85ee58c58337831182c887e Mon Sep 17 00:00:00 2001 From: Michael Wilkerson Date: Fri, 21 Oct 2022 15:57:27 -0700 Subject: [PATCH 3/3] replace special characters in tests - GitHub actions can't upload test files with special characters in the name, so replace all special characters with underscores (_) --- acceptance/framework/k8s/debug.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/acceptance/framework/k8s/debug.go b/acceptance/framework/k8s/debug.go index 338c6ce995..c1f0c5d7d6 100644 --- a/acceptance/framework/k8s/debug.go +++ b/acceptance/framework/k8s/debug.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "path/filepath" + "regexp" "testing" "github.com/gruntwork-io/terratest/modules/k8s" @@ -26,8 +27,14 @@ func WritePodsDebugInfoIfFailed(t *testing.T, kubectlOptions *k8s.KubectlOptions contextName := environment.KubernetesContextFromOptions(t, kubectlOptions) - // Create a directory for the test. - testDebugDirectory := filepath.Join(debugDirectory, t.Name(), contextName) + // Create a directory for the test, first remove special characters from test name + reg, err := regexp.Compile("[^A-Za-z0-9/_-]+") + if err != nil { + logger.Log(t, "unable to generate regex for test name special character replacement", "err", err) + } + tn := reg.ReplaceAllString(t.Name(), "_") + + testDebugDirectory := filepath.Join(debugDirectory, tn, contextName) require.NoError(t, os.MkdirAll(testDebugDirectory, 0755)) logger.Logf(t, "dumping logs, pod info, and envoy config for %s to %s", labelSelector, testDebugDirectory)