Skip to content

Commit

Permalink
Backport CI changes to 1.1.x (#12824)
Browse files Browse the repository at this point in the history
* Merge pull request #11889 from hashicorp/build-update-circle

build: upgrade circleci configuration

* Merge pull request #12299 from hashicorp/ci-parallel

ci: trade test parallelization for unconstrained gomaxprocs

* Merge pull request #12321 from hashicorp/ci-less-logging

ci: limit gotestsum to circle ci

* CI: build binaries for UI branches (#12594)

Build binaries for every code change, not just backend code
changes. This means that we'll have up-to-date compiled assets for
every commit available in CircleCI artifacts.

* cgutil test: reserve only a single CPU for AddAlloc test

Reserving the entire machine's worth of CPUs for the `AddAlloc` test
triggers a condition where the empty shared CPUs defaults to the
parent CPU set on some system configurations. This was done in `main`
as part of cgroups v2 work, but we need to backport this to earlier
branches in order to use the same machines across branches.

Co-authored-by: Seth Hoenig <seth.a.hoenig@gmail.com>
Co-authored-by: Tim Gross <tgross@hashicorp.com>
  • Loading branch information
3 people committed Apr 29, 2022
1 parent 16d6dec commit e50eea3
Show file tree
Hide file tree
Showing 411 changed files with 4,664 additions and 2,679 deletions.
3 changes: 3 additions & 0 deletions .changelog/11889.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
build: upgrade and speedup circleci configuration
```
23 changes: 5 additions & 18 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ version: 2.1
references:
# environment specific references - aim to avoid conflicts
go-machine-image: &go_machine_image
circleci/classic:201808-01
go-machine-recent-image: &go_machine_recent_image
ubuntu-1604:201903-01
ubuntu-2004:202111-02
go-windows-image: &go_windows_image
windows-server-2019-vs2019:stable

# common references
common_envs: &common_envs
GOMAXPROCS: 1
NOMAD_SLOW_TEST: 1
GOTESTSUM_JUNITFILE: /tmp/test-reports/results.xml
GOTESTSUM_JSONFILE: /tmp/test-reports/testjsonfile.json
Expand Down Expand Up @@ -289,7 +286,7 @@ jobs:
default: ""
executor:
type: string
default: "go-machine-recent"
default: "go-machine"
goarch:
type: string
default: "amd64"
Expand Down Expand Up @@ -513,6 +510,7 @@ executors:
working_directory: /go/src/github.com/hashicorp/nomad
docker:
- image: docker.mirror.hashicorp.services/golang:1.16.12
resource_class: medium
environment:
<<: *common_envs
GOPATH: /go
Expand All @@ -521,19 +519,12 @@ executors:
working_directory: ~/go/src/github.com/hashicorp/nomad
machine:
image: *go_machine_image
resource_class: large
environment: &machine_env
<<: *common_envs
GOPATH: /home/circleci/go
GOLANG_VERSION: 1.16.12

# uses a more recent image with unattended upgrades disabled properly
# but seems to break docker builds
go-machine-recent:
working_directory: ~/go/src/github.com/hashicorp/nomad
machine:
image: *go_machine_recent_image
environment: *machine_env

go-macos:
working_directory: ~/go/src/github.com/hashicorp/nomad
macos:
Expand All @@ -554,7 +545,7 @@ executors:
GOBIN: c:\gopath\bin
GOTESTSUM_PATH: c:\tmp\test-reports
GOLANG_VERSION: 1.16.12
GOTESTSUM_VERSION: 0.4.2
GOTESTSUM_VERSION: 1.7.0
VAULT_VERSION: 1.4.1

workflows:
Expand All @@ -567,7 +558,6 @@ workflows:
branches:
ignore:
- stable-website
- /^.-ui\b.*/

- lint-go:
# check branches are almost all the backend branches
Expand Down Expand Up @@ -636,9 +626,6 @@ workflows:
- test-machine:
name: "test-docker"
test_packages: "./drivers/docker"
# docker is misbehaving in docker-machine-recent image
# and we get unexpected failures
# e.g. https://circleci.com/gh/hashicorp/nomad/3854
executor: go-machine
filters: *backend_test_branches_filter
- test-machine:
Expand Down
27 changes: 18 additions & 9 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,29 @@ GIT_DIRTY := $(if $(shell git status --porcelain),+CHANGES)

GO_LDFLAGS := "-X github.com/hashicorp/nomad/version.GitCommit=$(GIT_COMMIT)$(GIT_DIRTY)"

ifneq (MSYS_NT,$(THIS_OS))
# GOPATH supports PATH style multi-paths; assume the first entry is favorable.
# Necessary because new Circle images override GOPATH with multiple values.
# See: https://discuss.circleci.com/t/gopath-is-set-to-multiple-directories/7174
GOPATH=$(shell go env GOPATH | cut -d: -f1)
endif

GO_TAGS ?=

ifeq ($(CI),true)
GO_TAGS := codegen_generated $(GO_TAGS)
endif

# Don't embed the Nomad UI when the NOMAD_NO_UI env var is set.
ifndef NOMAD_NO_UI
GO_TAGS := ui $(GO_TAGS)
endif

ifeq ($(CIRCLECI),true)
GO_TEST_CMD = $(if $(shell command -v gotestsum 2>/dev/null),gotestsum --,go test)
else
GO_TEST_CMD = go test
endif

ifeq ($(origin GOTEST_PKGS_EXCLUDE), undefined)
GOTEST_PKGS ?= "./..."
Expand All @@ -31,12 +47,6 @@ LAST_RELEASE ?= v1.1.12

default: help

ifeq ($(CI),true)
$(info Running in a CI environment, verbose mode is disabled)
else
VERBOSE="true"
endif

ifeq (Linux,$(THIS_OS))
ALL_TARGETS = linux_386 \
linux_amd64 \
Expand Down Expand Up @@ -108,7 +118,7 @@ deps: ## Install build and development dependencies
go install github.com/hashicorp/go-bindata/go-bindata@bf7910af899725e4938903fb32048c7c0b15f12e
go install github.com/elazarl/go-bindata-assetfs/go-bindata-assetfs@234c15e7648ff35458026de92b34c637bae5e6f7
go install github.com/a8m/tree/cmd/tree@fce18e2a750ea4e7f53ee706b1c3d9cbb22de79c
go install gotest.tools/gotestsum@v0.4.2
go install gotest.tools/gotestsum@v1.7.0
go install github.com/hashicorp/hcl/v2/cmd/hclfmt@v2.5.1
go install github.com/golang/protobuf/protoc-gen-go@v1.3.4
go install github.com/hashicorp/go-msgpack/codec/codecgen@v1.1.5
Expand Down Expand Up @@ -223,7 +233,6 @@ tidy:
.PHONY: dev
dev: GOOS=$(shell go env GOOS)
dev: GOARCH=$(shell go env GOARCH)
dev: GOPATH=$(shell go env GOPATH)
dev: DEV_TARGET=pkg/$(GOOS)_$(GOARCH)/nomad
dev: hclfmt ## Build for the current development platform
@echo "==> Removing old development build..."
Expand Down Expand Up @@ -278,7 +287,7 @@ test-nomad: dev ## Run Nomad test suites

.PHONY: test-nomad-module
test-nomad-module: dev ## Run Nomad test suites on a sub-module
@echo "==> Running Nomad test suites on sub-module:"
@echo "==> Running Nomad test suites on sub-module $(GOTEST_MOD)"
@cd $(GOTEST_MOD) && $(if $(ENABLE_RACE),GORACE="strip_path_prefix=$(GOPATH)/src") $(GO_TEST_CMD) \
$(if $(ENABLE_RACE),-race) $(if $(VERBOSE),-v) \
-cover \
Expand Down
19 changes: 19 additions & 0 deletions acl/acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package acl
import (
"testing"

"github.com/hashicorp/nomad/ci"
"github.com/stretchr/testify/assert"
)

func TestCapabilitySet(t *testing.T) {
ci.Parallel(t)

var cs capabilitySet = make(map[string]struct{})

// Check no capabilities by default
Expand All @@ -28,6 +31,8 @@ func TestCapabilitySet(t *testing.T) {
}

func TestMaxPrivilege(t *testing.T) {
ci.Parallel(t)

type tcase struct {
Privilege string
PrecedenceOver []string
Expand Down Expand Up @@ -60,6 +65,8 @@ func TestMaxPrivilege(t *testing.T) {
}

func TestACLManagement(t *testing.T) {
ci.Parallel(t)

assert := assert.New(t)

// Create management ACL
Expand Down Expand Up @@ -88,6 +95,8 @@ func TestACLManagement(t *testing.T) {
}

func TestACLMerge(t *testing.T) {
ci.Parallel(t)

assert := assert.New(t)

// Merge read + write policy
Expand Down Expand Up @@ -222,6 +231,8 @@ quota {
`

func TestAllowNamespace(t *testing.T) {
ci.Parallel(t)

tests := []struct {
Policy string
Allow bool
Expand Down Expand Up @@ -264,6 +275,8 @@ func TestAllowNamespace(t *testing.T) {
}

func TestWildcardNamespaceMatching(t *testing.T) {
ci.Parallel(t)

tests := []struct {
Policy string
Allow bool
Expand Down Expand Up @@ -315,6 +328,8 @@ func TestWildcardNamespaceMatching(t *testing.T) {
}

func TestWildcardHostVolumeMatching(t *testing.T) {
ci.Parallel(t)

tests := []struct {
Policy string
Allow bool
Expand Down Expand Up @@ -365,6 +380,8 @@ func TestWildcardHostVolumeMatching(t *testing.T) {
}
}
func TestACL_matchingCapabilitySet_returnsAllMatches(t *testing.T) {
ci.Parallel(t)

tests := []struct {
Policy string
NS string
Expand Down Expand Up @@ -411,6 +428,8 @@ func TestACL_matchingCapabilitySet_returnsAllMatches(t *testing.T) {
}

func TestACL_matchingCapabilitySet_difference(t *testing.T) {
ci.Parallel(t)

tests := []struct {
Policy string
NS string
Expand Down
5 changes: 5 additions & 0 deletions acl/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import (
"strings"
"testing"

"github.com/hashicorp/nomad/ci"
"github.com/stretchr/testify/assert"
)

func TestParse(t *testing.T) {
ci.Parallel(t)

type tcase struct {
Raw string
ErrStr string
Expand Down Expand Up @@ -333,6 +336,8 @@ func TestParse(t *testing.T) {
}

func TestParse_BadInput(t *testing.T) {
ci.Parallel(t)

inputs := []string{
`namespace "\500" {}`,
}
Expand Down
28 changes: 28 additions & 0 deletions ci/slow.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package ci

import (
"os"
"strconv"
"testing"
)

// SkipSlow skips a slow test unless NOMAD_SLOW_TEST is set to a true value.
func SkipSlow(t *testing.T, reason string) {
value := os.Getenv("NOMAD_SLOW_TEST")
run, err := strconv.ParseBool(value)
if !run || err != nil {
t.Skipf("Skipping slow test: %s", reason)
}
}

// Parallel runs t in parallel, unless CI is set to a true value.
//
// In CI (CircleCI / GitHub Actions) we get better performance by running tests
// in serial while not restricting GOMAXPROCS.
func Parallel(t *testing.T) {
value := os.Getenv("CI")
isCI, err := strconv.ParseBool(value)
if !isCI || err != nil {
t.Parallel()
}
}
11 changes: 10 additions & 1 deletion client/acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/hashicorp/nomad/acl"
"github.com/hashicorp/nomad/ci"
"github.com/hashicorp/nomad/client/config"
"github.com/hashicorp/nomad/helper/uuid"
"github.com/hashicorp/nomad/nomad/mock"
Expand All @@ -13,6 +14,8 @@ import (
)

func TestClient_ACL_resolveTokenValue(t *testing.T) {
ci.Parallel(t)

s1, _, _, cleanupS1 := testACLServer(t, nil)
defer cleanupS1()
testutil.WaitForLeader(t, s1.RPC)
Expand Down Expand Up @@ -62,6 +65,8 @@ func TestClient_ACL_resolveTokenValue(t *testing.T) {
}

func TestClient_ACL_resolvePolicies(t *testing.T) {
ci.Parallel(t)

s1, _, root, cleanupS1 := testACLServer(t, nil)
defer cleanupS1()
testutil.WaitForLeader(t, s1.RPC)
Expand Down Expand Up @@ -102,6 +107,8 @@ func TestClient_ACL_resolvePolicies(t *testing.T) {
}

func TestClient_ACL_ResolveToken_Disabled(t *testing.T) {
ci.Parallel(t)

s1, _, cleanupS1 := testServer(t, nil)
defer cleanupS1()
testutil.WaitForLeader(t, s1.RPC)
Expand All @@ -118,6 +125,8 @@ func TestClient_ACL_ResolveToken_Disabled(t *testing.T) {
}

func TestClient_ACL_ResolveToken(t *testing.T) {
ci.Parallel(t)

s1, _, _, cleanupS1 := testACLServer(t, nil)
defer cleanupS1()
testutil.WaitForLeader(t, s1.RPC)
Expand Down Expand Up @@ -167,7 +176,7 @@ func TestClient_ACL_ResolveToken(t *testing.T) {
}

func TestClient_ACL_ResolveSecretToken(t *testing.T) {
t.Parallel()
ci.Parallel(t)

s1, _, _, cleanupS1 := testACLServer(t, nil)
defer cleanupS1()
Expand Down
Loading

0 comments on commit e50eea3

Please sign in to comment.