Skip to content

Commit

Permalink
Restore Kubernetes Integration tests (gravitational#25624)
Browse files Browse the repository at this point in the history
* Restore Kubernetes Integration tests

This PR re-enables the Kubernetes integrations tests using a KinD
(Kubernetes in Docker) cluster.

New steps have been introduced to GitHub's Integrations (Non-Root)
Action that configure the KinD cluster using
[`helm/kind-action`](https://github.com/helm/kind-action) and do some
network configurations allowing the container where tests run to connect
to the KinD control plane.

This PR also fixes some of the tests and fixes a bug that affected
joining operations when the target service was a legacy kubernetes
proxy. Some improvements will be introduced in future patches to improve
the logic and reduce the time required for the tests to run.

Fixes gravitational#25539

* fix data race in spdystream dep

* address feedback

* remove docker installation

* fix test
  • Loading branch information
tigrato authored May 12, 2023
1 parent 3cae807 commit 32d8d5f
Show file tree
Hide file tree
Showing 9 changed files with 265 additions and 32 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/kube-integration-tests-non-root-bypass.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# This workflow is required to ensure that required Github check passes even if
# the actual "Kube Integration Tests (Non-root)" workflow skipped due to path filtering.
# Otherwise it will stay forever pending.
#
# See "Handling skipped but required checks" for more info:
#
# https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/troubleshooting-required-status-checks#handling-skipped-but-required-checks
#
# Note both workflows must have the same name.

name: Kube Integration Tests (Non-root)
run-name: Skip Kube Integration Tests (Non-root) - ${{ github.run_id }} - @${{ github.actor }}

on:
pull_request:
paths-ignore:
- '.github/workflows/kube-integration-tests-non-root.yaml'
- '**.go'
- 'go.mod'
- 'go.sum'
- 'build.assets/Makefile'
- 'build.assets/Dockerfile*'
- 'Makefile'
merge_group:
paths-ignore:
- '.github/workflows/kube-integration-tests-non-root.yaml'
- '**.go'
- 'go.mod'
- 'go.sum'
- 'build.assets/Makefile'
- 'build.assets/Dockerfile*'
- 'Makefile'

jobs:
test:
name: Kube Integration Tests (Non-root)
runs-on: ubuntu-latest

permissions:
contents: none

steps:
- run: 'echo "No changes to verify"'
87 changes: 87 additions & 0 deletions .github/workflows/kube-integration-tests-non-root.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Kube Integration Tests (Non-root)
run-name: Kube Integration Tests (Non-root) - ${{ github.run_id }} - @${{ github.actor }}

on:
push:
branches:
- master
- branch/*
pull_request:
paths:
- '.github/workflows/kube-integration-tests-non-root.yaml'
- '**.go'
- 'go.mod'
- 'go.sum'
- 'build.assets/Makefile'
- 'build.assets/Dockerfile*'
- 'Makefile'
merge_group:
paths:
- '.github/workflows/kube-integration-tests-non-root.yaml'
- '**.go'
- 'go.mod'
- 'go.sum'
- 'build.assets/Makefile'
- 'build.assets/Dockerfile*'
- 'Makefile'

env:
TEST_KUBE: true
KUBECONFIG: /home/.kube/config

jobs:
test:
name: Kube Integration Tests (Non-root)
if: ${{ !startsWith(github.head_ref, 'dependabot/') }}
runs-on: ubuntu-22.04-16core

permissions:
contents: read
packages: read

container:
image: ghcr.io/gravitational/teleport-buildbox:teleport13
env:
WEBASSETS_SKIP_BUILD: 1
options: --cap-add=SYS_ADMIN --privileged

steps:
- name: Checkout Teleport
uses: actions/checkout@v3

- name: Prepare workspace
uses: ./.github/actions/prepare-workspace

- name: Chown
run: |
mkdir -p $(go env GOMODCACHE)
mkdir -p $(go env GOCACHE)
chown -Rf ci:ci ${GITHUB_WORKSPACE} $(go env GOMODCACHE) $(go env GOCACHE)
continue-on-error: true

- name: Create KinD cluster
uses: helm/[email protected]
with:
cluster_name: kind
config: fixtures/kind/config.yaml

# The current container where tests run isn't linked to the KinD network and
# we won't be able to access the KinD control plane without linking them.
# This step is required because our tests run in teleport-buildbox container
# and by default the KinD container network isn't exposed to it.
# Connecting the network allow us to access the control plane using DNS kind-control-plane.
# It also copies the default kubeconfig and places it in /home/.kube so ci user
# is able to access it.
- name: Link test container to KinD network
run: |
docker network connect kind $(cat /etc/hostname)
kubectl config set-cluster kind-kind --server=https://kind-control-plane:6443
kubectl cluster-info
kubectl apply -f fixtures/ci-teleport-rbac/ci-teleport.yaml
cp -r $HOME/.kube /home/
chown -R ci:ci /home/.kube
- name: Run tests
timeout-minutes: 40
run: |
runuser -u ci -g ci make rdpclient integration-kube
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,20 @@ integration: $(TEST_LOG_DIR) $(RENDER_TESTS)
| tee $(TEST_LOG_DIR)/integration.json \
| $(RENDER_TESTS) -report-by test

#
# Integration tests that run Kubernetes tests in order to complete successfully
# are run separately to all other integration tests.
#
INTEGRATION_KUBE_REGEX := TestKube.*
.PHONY: integration-kube
integration-kube: FLAGS ?= -v -race
integration-kube: PACKAGES = $(shell go list ./... | grep 'integration\([^s]\|$$\)')
integration-kube: $(TEST_LOG_DIR) $(RENDER_TESTS)
@echo KUBECONFIG is: $(KUBECONFIG), TEST_KUBE: $(TEST_KUBE)
$(CGOFLAG) go test -json -run "$(INTEGRATION_KUBE_REGEX)" $(PACKAGES) $(FLAGS) \
| tee $(TEST_LOG_DIR)/integration-kube.json \
| $(RENDER_TESTS) -report-by test

#
# Integration tests which need to be run as root in order to complete successfully
# are run separately to all other integration tests. Need a TTY to work.
Expand Down
5 changes: 5 additions & 0 deletions build.assets/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ integration-root: buildbox
docker run $(DOCKERFLAGS) -t $(BUILDBOX) \
/bin/bash -c "make -C $(SRCDIR) FLAGS='-cover' integration-root"

.PHONY:integration-kube
integration-kube: buildbox
docker run $(DOCKERFLAGS) -t $(BUILDBOX) \
/bin/bash -c "make -C $(SRCDIR) FLAGS='-cover' integration-kube"

#
# Runs linters on new changes inside a build container.
#
Expand Down
6 changes: 6 additions & 0 deletions fixtures/kind/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
apiServerAddress: '127.0.0.1'
apiServerPort: 6443

3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,9 @@ replace (
github.com/julienschmidt/httprouter => github.com/gravitational/httprouter v1.3.1-0.20220408074523-c876c5e705a5
github.com/keys-pub/go-libfido2 => github.com/gravitational/go-libfido2 v1.5.3-0.20230202181331-c71192ef1c8a
github.com/microsoft/go-mssqldb => github.com/gravitational/go-mssqldb v0.11.1-0.20230331180905-0f76f1751cd3
// replace module github.com/moby/spdystream until https://github.com/moby/spdystream/pull/91 merges and deps are updated
// otherwise tests fail with a data race detection.
github.com/moby/spdystream => github.com/gravitational/spdystream v0.0.0-20230512133543-4e46862ca9bf
github.com/sirupsen/logrus => github.com/gravitational/logrus v1.4.4-0.20210817004754-047e20245621
github.com/vulcand/predicate => github.com/gravitational/predicate v1.3.0
// Use our internal crypto fork, to work around the issue with OpenSSH <= 7.6 mentioned here: https://github.com/golang/go/issues/53391
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,8 @@ github.com/gravitational/redis/v9 v9.0.0-teleport.3 h1:Eg/j3jiNUZ558KDXOqzF682EF
github.com/gravitational/redis/v9 v9.0.0-teleport.3/go.mod h1:8et+z03j0l8N+DvsVnclzjf3Dl/pFHgRk+2Ct1qw66A=
github.com/gravitational/roundtrip v1.0.2 h1:eOCY0NEKKaB0ksJmvhO6lPMFz1pIIef+vyPBTBROQ5c=
github.com/gravitational/roundtrip v1.0.2/go.mod h1:fuI1booM2hLRA/B/m5MRAPOU6mBZNYcNycono2UuTw0=
github.com/gravitational/spdystream v0.0.0-20230512133543-4e46862ca9bf h1:aXnqDSit8L1qhI0+QdbJh+MTUFKXG7qbkZXnfr7L96A=
github.com/gravitational/spdystream v0.0.0-20230512133543-4e46862ca9bf/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c=
github.com/gravitational/trace v1.2.1 h1:Iaf43aqbKV5H8bdiRs1qByjEHgAfADJ0lt0JwRyu+q8=
github.com/gravitational/trace v1.2.1/go.mod h1:n0ijrq6psJY0sOI/NzLp+xdd8xl79jjwzVOFHDY6+kQ=
github.com/gravitational/ttlmap v0.0.0-20171116003245-91fd36b9004c h1:C2iWDiod8vQ3YnOiCdMP9qYeg2UifQ8KSk36r0NswSE=
Expand Down Expand Up @@ -1072,8 +1074,6 @@ github.com/mitchellh/mapstructure v1.3.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RR
github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/moby/spdystream v0.2.0 h1:cjW1zVyyoiM0T7b6UoySUFqzXMoqRckQtXwGPiBhOM8=
github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c=
github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down
Loading

0 comments on commit 32d8d5f

Please sign in to comment.