Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport] Google CloudBuild support (#9090) #9165

Merged
merged 6 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .cloudbuild/ci/doc-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
steps:
- name: quay.io/gravitational/next:main
id: docs-test
env:
- WITH_EXTERNAL_LINKS=true
dir: /src
args: ['yarn', 'remark', '/workspace/docs/pages/**/*.mdx', '--frail']
timeout: 10m
29 changes: 29 additions & 0 deletions .cloudbuild/ci/integration-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
steps:
# Run non-root integration tests. The root user is selected by docker image.
- name: us-docker.pkg.dev/ci-account/teleport/buildbox-root:v0.1.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this is fine, but should we create a teleport8-v0.1.0 too?

id: root-integration-test
args: ['make', 'rdpclient', 'integration-root']
timeout: 10m

# Reconfigure the workspace for the non-root user
- name: us-docker.pkg.dev/ci-account/teleport/buildbox-root:v0.1.0
id: reconfigure-for-nonroot-user
args: ['chown', '-R', 'ci:ci', '/workspace']

# Run non-root integration tests. The non-root user is selected by docker image.
- name: us-docker.pkg.dev/ci-account/teleport/buildbox-nonroot:v0.1.0
id: nonroot-integration-test
env:
- TELEPORT_ETCD_TEST="yes"
entrypoint: '/bin/bash'
args:
- '-c'
- '(make run-etcd &); sleep 1; make integration'
timeout: 15m

timeout: 20m
options:
env:
- GOMODCACHE=/workspace/.gomodcacheci
machineType: E2_HIGHCPU_32

6 changes: 6 additions & 0 deletions .cloudbuild/ci/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
steps:
- name: us-docker.pkg.dev/ci-account/teleport/buildbox-root:v0.1.0
id: lint
args: ['make', 'lint-go', 'lint-api']
options:
machineType: 'E2_HIGHCPU_32'
14 changes: 14 additions & 0 deletions .cloudbuild/ci/unit-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
steps:
- name: us-docker.pkg.dev/ci-account/teleport/buildbox-root:v0.1.0
id: unit-test
env:
- TELEPORT_ETCD_TEST="yes"
entrypoint: '/bin/bash'
args:
- '-c'
- '(make run-etcd &); sleep 1; make test'
timeout: 15m
timeout: 15m
options:
machineType: 'E2_HIGHCPU_32'

16 changes: 10 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,9 @@ test-go: FLAGS ?= '-race'
test-go: PACKAGES := $(shell go list ./... | grep -v integration)
test-go: CHAOS_FOLDERS := $(shell find . -type f -name '*chaos*.go' -not -path '*/vendor/*' | xargs dirname | uniq)
test-go: $(VERSRC)
$(CGOFLAG) go test -p 4 -cover -json -tags "$(PAM_TAG) $(FIPS_TAG) $(BPF_TAG) $(ROLETESTER_TAG) $(RDPCLIENT_TAG)" $(PACKAGES) $(FLAGS) $(ADDFLAGS) \
$(CGOFLAG) go test -cover -json -tags "$(PAM_TAG) $(FIPS_TAG) $(BPF_TAG) $(ROLETESTER_TAG) $(RDPCLIENT_TAG)" $(PACKAGES) $(FLAGS) $(ADDFLAGS) \
| go run build.assets/render-tests/main.go
$(CGOFLAG) go test -p 4 -cover -json -tags "$(PAM_TAG) $(FIPS_TAG) $(BPF_TAG) $(ROLETESTER_TAG) $(RDPCLIENT_TAG)" -test.run=TestChaos $(CHAOS_FOLDERS) \
$(CGOFLAG) go test -cover -json -tags "$(PAM_TAG) $(FIPS_TAG) $(BPF_TAG) $(ROLETESTER_TAG) $(RDPCLIENT_TAG)" -test.run=TestChaos $(CHAOS_FOLDERS) \
| go run build.assets/render-tests/main.go

#
Expand All @@ -466,7 +466,7 @@ test-go-root: ensure-webassets bpf-bytecode roletester rdpclient
test-go-root: FLAGS ?= '-race'
test-go-root: PACKAGES := $(shell go list $(ADDFLAGS) ./... | grep -v integration)
test-go-root: $(VERSRC)
$(CGOFLAG) go test -p 4 -run "$(UNIT_ROOT_REGEX)" -tags "$(PAM_TAG) $(FIPS_TAG) $(BPF_TAG) $(ROLETESTER_TAG) $(RDPCLIENT_TAG)" $(PACKAGES) $(FLAGS) $(ADDFLAGS)
$(CGOFLAG) go test -run "$(UNIT_ROOT_REGEX)" -tags "$(PAM_TAG) $(FIPS_TAG) $(BPF_TAG) $(ROLETESTER_TAG) $(RDPCLIENT_TAG)" $(PACKAGES) $(FLAGS) $(ADDFLAGS)

# Runs API Go tests. These have to be run separately as the package name is different.
#
Expand All @@ -475,7 +475,7 @@ test-api:
test-api: FLAGS ?= '-race'
test-api: PACKAGES := $(shell cd api && go list ./...)
test-api: $(VERSRC)
$(CGOFLAG) go test -p 4 -tags "$(PAM_TAG) $(FIPS_TAG) $(BPF_TAG) $(ROLETESTER_TAG)" $(PACKAGES) $(FLAGS) $(ADDFLAGS)
$(CGOFLAG) go test -tags "$(PAM_TAG) $(FIPS_TAG) $(BPF_TAG) $(ROLETESTER_TAG)" $(PACKAGES) $(FLAGS) $(ADDFLAGS)

# Find and run all shell script unit tests (using https://github.com/bats-core/bats-core)
.PHONY: test-sh
Expand All @@ -487,6 +487,10 @@ test-sh:
fi; \
find . -iname "*.bats" -exec dirname {} \; | uniq | xargs -t -L1 bats $(BATSFLAGS)


.PHONY: run-etcd
run-etcd:
examples/etcd/start-etcd.sh
#
# Integration tests. Need a TTY to work.
# Any tests which need to run as root must be skipped during regular integration testing.
Expand All @@ -496,7 +500,7 @@ integration: FLAGS ?= -v -race
integration: PACKAGES := $(shell go list ./... | grep integration)
integration:
@echo KUBECONFIG is: $(KUBECONFIG), TEST_KUBE: $(TEST_KUBE)
$(CGOFLAG) go test -p 4 -tags "$(PAM_TAG) $(FIPS_TAG) $(BPF_TAG) $(ROLETESTER_TAG) $(RDPCLIENT_TAG)" $(PACKAGES) $(FLAGS)
$(CGOFLAG) go test -timeout 30m -tags "$(PAM_TAG) $(FIPS_TAG) $(BPF_TAG) $(ROLETESTER_TAG) $(RDPCLIENT_TAG)" $(PACKAGES) $(FLAGS)

#
# Integration tests which need to be run as root in order to complete successfully
Expand All @@ -507,7 +511,7 @@ INTEGRATION_ROOT_REGEX := ^TestRoot
integration-root: FLAGS ?= -v -race
integration-root: PACKAGES := $(shell go list ./... | grep integration)
integration-root:
$(CGOFLAG) go test -p 4 -run "$(INTEGRATION_ROOT_REGEX)" $(PACKAGES) $(FLAGS)
$(CGOFLAG) go test -run "$(INTEGRATION_ROOT_REGEX)" $(PACKAGES) $(FLAGS)

#
# Lint the source code.
Expand Down
2 changes: 1 addition & 1 deletion api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ func (c *Config) CheckAndSetDefaults() error {
}

if c.KeepAlivePeriod == 0 {
c.KeepAlivePeriod = defaults.ServerKeepAliveTTL
c.KeepAlivePeriod = defaults.ServerKeepAliveTTL()
}
if c.KeepAliveCount == 0 {
c.KeepAliveCount = defaults.KeepAliveCountMax
Expand Down
31 changes: 27 additions & 4 deletions api/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
package defaults

import (
"sync"
"time"

"github.com/gravitational/teleport/api/constants"
Expand Down Expand Up @@ -50,17 +51,39 @@ const (
)

var (
// ServerKeepAliveTTL is a period between server keep-alives,
moduleLock sync.RWMutex

// serverKeepAliveTTL is a period between server keep-alives,
// when servers announce only presence without sending full data
ServerKeepAliveTTL = 60 * time.Second
serverKeepAliveTTL = 60 * time.Second

// KeepAliveInterval is interval at which Teleport will send keep-alive
// keepAliveInterval is interval at which Teleport will send keep-alive
// messages to the client. The default interval of 5 minutes (300 seconds) is
// set to help keep connections alive when using AWS NLBs (which have a default
// timeout of 350 seconds)
KeepAliveInterval = 5 * time.Minute
keepAliveInterval = 5 * time.Minute
)

func SetTestTimeouts(svrKeepAliveTTL, keepAliveTick time.Duration) {
moduleLock.Lock()
defer moduleLock.Unlock()

serverKeepAliveTTL = svrKeepAliveTTL
keepAliveInterval = keepAliveTick
}

func ServerKeepAliveTTL() time.Duration {
moduleLock.RLock()
defer moduleLock.RUnlock()
return serverKeepAliveTTL
}

func KeepAliveInterval() time.Duration {
moduleLock.RLock()
defer moduleLock.RUnlock()
return keepAliveInterval
}

// EnhancedEvents returns the default list of enhanced events.
func EnhancedEvents() []string {
return []string{
Expand Down
2 changes: 1 addition & 1 deletion api/types/networking.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func (c *ClusterNetworkingConfigV2) CheckAndSetDefaults() error {

// Set the keep-alive interval and max missed keep-alives.
if c.Spec.KeepAliveInterval.Duration() == 0 {
c.Spec.KeepAliveInterval = NewDuration(defaults.KeepAliveInterval)
c.Spec.KeepAliveInterval = NewDuration(defaults.KeepAliveInterval())
}
if c.Spec.KeepAliveCountMax == 0 {
c.Spec.KeepAliveCountMax = int64(defaults.KeepAliveCountMax)
Expand Down
12 changes: 9 additions & 3 deletions integration/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,17 @@ const (
)

// SetTestTimeouts affects global timeouts inside Teleport, making connections
// work faster but consuming more CPU (useful for integration testing)
// work faster but consuming more CPU (useful for integration testing).
// NOTE: This function modifies global values for timeouts, etc. If your tests
// call this function, they MUST NOT BE RUN IN PARALLEL, as they may stomp on
// other tests.
func SetTestTimeouts(t time.Duration) {
apidefaults.KeepAliveInterval = t
// TODO(tcsc): Remove this altogether and replace with per-test timeout
// config (as per #8913)

apidefaults.SetTestTimeouts(t, t)

defaults.ResyncInterval = t
apidefaults.ServerKeepAliveTTL = t
defaults.SessionRefreshPeriod = t
defaults.HeartbeatCheckPeriod = t
defaults.CachePollPeriod = t
Expand Down
Loading