Telepresence combined with GitHub Actions allows you to run integration tests in your CI pipeline without having to run any dependant service. By connecting to the target Kubernetes cluster, intercepting traffic to the remote service and sending it to an instance of the service running in CI you will be able to test bugfixes, updates and features very easily.
The v1.1.0 release contains the following changes
- Fix issues with Ambassador Cloud access needed during run.
- Move namespace option from
intercept
action toconnect
action (Telepresence 2.16) - Remove the (undocumented)
configure
action. - Add integration tests.
The v1.0.0 of Telepresence GitHub Actions contains individual actions to:
- Install the Telepresence binary in the Github runner.
- Helm install the telepresence traffic manager in the cluster.
- Connect to a remote Kubernetes cluster.
- Log into Ambassador and create a personal intercept.
- Intercept traffic of service running in the K8s cluster and redirect it a service instance running in CI.
See the Telepresence GitHub actions documentation page for information about how to use these actions and build an integration tests workflow for your repository. Note: The version v1.0.0 only supports Ubuntu runners at moment.
Get a free Ambassador Cloud account. Register here to get a free account. No credit card required.
The following is an example of a workflow that:
- Checks out the repository code.
- Has a placeholder step to run a service during CI.
- Creates the /opt/kubeconfig file with the contents of the secrets.KUBECONFIG_FILE to make it available for Telepresence.
- Installs Telepresence.
- Runs Telepresence Connect.
- Logs into Ambassador Telepresence.
- Intercepts traffic to the service running in the remote cluster.
- A placeholder for an action that would run integration tests, like making HTTP requests to your running service and verify it works while dependant services run in the remote cluster.
name: Run Integration Tests
on:
push:
branches-ignore:
- 'main'
jobs:
my-job:
name: Run Integration Test using Remote Cluster
runs-on: ubuntu-latest
env:
TELEPRESENCE_API_KEY: ${{ secrets.TELEPRESENCE_API_KEY }}
KUBECONFIG_FILE: ${{ secrets.KUBECONFIG_FILE }}
KUBECONFIG: /opt/kubeconfig
steps:
- name : Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
#---- here run your custom command to run your service
#- name: Run your service to test
# shell: bash
# run: ./run_local_service
#----
# First you need to log in to Telepresence, with your api key
- name: Create kubeconfig file
run: |
cat <<EOF > /opt/kubeconfig
${{ env.KUBECONFIG_FILE }}
EOF
- name: Install Telepresence
uses: datawire/telepresence-actions/install@v1.1
with:
version: 2.19.0 # Change the version number here according to the version of Telepresence in your cluster or omit this parameter to install the latest version
- name: Install Traffic Manager
uses: datawire/telepresence-actions/helm@v1.1
- name: Telepresence connect
uses: datawire/telepresence-actions/connect@v1.1
- name: Login
uses: datawire/telepresence-actions/login@v1.1
with:
telepresence_api_key: ${{ secrets.TELEPRESENCE_API_KEY }}
- name: Intercept the service
uses: datawire/telepresence-actions/intercept@v1.1
with:
service_name: service-name
service_port: 8081:8080
http_header: "x-telepresence-intercept-test=service-intercepted" # Custom HTTP header name and value that will identify traffic desired to go to the local service instace.
print_logs: true # Flag to instruct the action to print out Telepresence logs and export an artifact with them
#---- Run a custom command to run integration tests.
#- name: Run integrations test
# shell: bash
# run: ./run_integration_test
#----