Skip to content

Commit

Permalink
Mw/cherry pick ac updates (#1649)
Browse files Browse the repository at this point in the history
* removed make target for GitHub, no longer needed

* 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

* 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 (_)
  • Loading branch information
wilkermichael authored Oct 25, 2022
1 parent ef1ca6f commit e8f2490
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 33 deletions.
19 changes: 17 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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:
Expand Down
15 changes: 7 additions & 8 deletions acceptance/framework/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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()
}
1 change: 0 additions & 1 deletion acceptance/framework/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
11 changes: 9 additions & 2 deletions acceptance/framework/k8s/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"path/filepath"
"regexp"
"testing"

"github.com/gruntwork-io/terratest/modules/k8s"
Expand All @@ -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)
Expand Down
20 changes: 0 additions & 20 deletions control-plane/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e8f2490

Please sign in to comment.