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

Oliver m king patch 22 #96

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
107 changes: 107 additions & 0 deletions .github/workflows/e2ev2-provision-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: E2E Version 2 Provision and Test

on:
workflow_call:
inputs:
ref:
type: string
skipRefCheck:
type: boolean
default: true
name:
type: string
required: true

permissions:
id-token: write

jobs:
provision:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.ref }}

- uses: actions/setup-go@v4
with:
go-version: '~1.20.3'
cache-dependency-path: "**/*.sum"

- name: Azure login
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

- name: Provision Infrastructure
shell: bash
run: |
cd testing/e2e
go run ./main.go infra --subscription="${{ secrets.AZURE_SUBSCRIPTION_ID }}" --tenant="${{ secrets.AZURE_TENANT_ID }}" --names="${{ inputs.name }}" --infra-file="./infra.json"
if:
(github.event_name == 'repository_dispatch' &&
github.event.client_payload.slash_command.args.named.sha != '' &&
contains(github.event.client_payload.pull_request.head.sha, github.event.client_payload.slash_command.args.named.sha)) ||
inputs.skipRefCheck

- name: Ensure ref
uses: actions/github-script@v6
if: ${{ !((github.event_name == 'repository_dispatch' && github.event.client_payload.slash_command.args.named.sha != '' && contains(github.event.client_payload.pull_request.head.sha, github.event.client_payload.slash_command.args.named.sha)) || inputs.skipRefCheck) }}
with:
script: core.setFailed('Ref is not latest')

- name: Upload infra file
uses: actions/upload-artifact@v3
with:
name: infra
path: testing/e2e/infra.json
test:
needs: provision
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.ref }}

- uses: actions/setup-go@v4
with:
go-version: '~1.20.3'

- name: Azure login
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

- uses: actions/download-artifact@master
with:
name: infra
path: testing/e2e/infra.json

- name: Test
shell: bash
id: test
run: |
cd testing/e2e
go run ./main.go deploy --infra-file="./infra.json"
if:
(github.event_name == 'repository_dispatch' &&
github.event.client_payload.slash_command.args.named.sha != '' &&
contains(github.event.client_payload.pull_request.head.sha, github.event.client_payload.slash_command.args.named.sha)) ||
inputs.skipRefCheck

- name: Upload logs
uses: actions/upload-artifact@v3
if: always() && steps.test.outcome == 'failure'
with:
name: logs
path: testing/e2e/job-app-routing-operator-e2e.log

- name: Ensure ref
uses: actions/github-script@v6
if: ${{ !((github.event_name == 'repository_dispatch' && github.event.client_payload.slash_command.args.named.sha != '' && contains(github.event.client_payload.pull_request.head.sha, github.event.client_payload.slash_command.args.named.sha)) || inputs.skipRefCheck) }}
with:
script: core.setFailed('Ref is not latest')
54 changes: 54 additions & 0 deletions .github/workflows/e2ev2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: E2E Version 2 Test

on:
workflow_call:
inputs:
ref:
type: string
skipRefCheck:
type: boolean
default: true

permissions:
id-token: write

jobs:
plan-infra:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.ref }}

- uses: actions/setup-go@v4
with:
go-version: '~1.20.3'
cache-dependency-path: "**/*.sum"

- run: |
cd testing/e2e
go run ./main.go matrix
shell: bash
id: matrix
if:
(github.event_name == 'repository_dispatch' &&
github.event.client_payload.slash_command.args.named.sha != '' &&
contains(github.event.client_payload.pull_request.head.sha, github.event.client_payload.slash_command.args.named.sha)) ||
inputs.skipRefCheck

- name: Ensure ref
uses: actions/github-script@v6
if: ${{ !((github.event_name == 'repository_dispatch' && github.event.client_payload.slash_command.args.named.sha != '' && contains(github.event.client_payload.pull_request.head.sha, github.event.client_payload.slash_command.args.named.sha)) || inputs.skipRefCheck) }}
with:
script: core.setFailed('Ref is not latest')
test:
needs: plan-infra
strategy:
fail-fast: false # this is false because we usually want to retry at individual infra level if there is a failure and it helps to see if only one infra is failing
matrix: ${{fromJson(needs.plan-infra.outputs.matrix)}}
uses: ./.github/workflows/e2ev2-provision-test.yaml
with:
name: ${{ matrix.name }}
secrets: inherit
6 changes: 5 additions & 1 deletion .github/workflows/pr-validate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ jobs:
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
uses: ./.github/workflows/e2e.yaml
secrets: inherit
e2eV2:
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
uses: ./.github/workflows/e2ev2.yaml
secrets: inherit
status:
permissions:
checks: write
pull-requests: read
needs: [e2e]
needs: [e2e, e2eV2]
runs-on: ubuntu-latest
steps:
- name: Update status
Expand Down
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ clean:
dev:
terraform --version
cd devenv && mkdir -p state && cd tf && terraform init && terraform apply -auto-approve -var="clustertype=$(CLUSTER_TYPE)"
./devenv/scripts/deploy_operator.sh
# ./devenv/scripts/deploy_operator.sh

push:
echo "$(shell cat devenv/state/registry.txt)/app-routing-operator:$(shell date +%s)" > devenv/state/operator-image-tag.txt
Expand Down Expand Up @@ -50,3 +50,14 @@ all-tests:
make clean
./devenv/scripts/run_public_cluster.sh

SUBSCRIPTION = ""
TENANT = ""
INFRAS = "basic cluster"
INFRA_FILE = "./infra-config.json"

# e2ev2 is the new e2e test framework. It will completely replace the old e2e test framework soon
e2ev2-infra:
(cd testing/e2e && go run ./main.go infra --subscription=$(SUBSCRIPTION) --tenant=$(TENANT) --names=$(INFRAS) --infra-file=$(INFRA_FILE))

e2ev2-test:
(cd testing/e2e && go run ./main.go deploy --infra-file=$(INFRA_FILE))
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ A Kubernetes operator that manages resources related to AKS Application Routing

## Docs

View the [docs](docs/) folder for more information.
View the [docs](docs/) folder for more information. adfasdf

## Contributing

Expand Down
Binary file added docs/e2e-jobs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 67 additions & 0 deletions docs/e2e.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

# E2E

E2E tests the operator's capabilities in a real AKS environment and also functions as integration tests ensuring each part of the operator works together.

E2E is ran automatically on every PR. See [GitHub Runner](#-github-runner).

You can also run E2E locally. See [Local E2E](#-local-e2e).

## Architecture

### Major Steps

E2e is designed so that every major step is run in a separate GitHub Job. This allows for easy retries and makes it a lot more obvious about which step failed. It also means logs are easier to read.

![e2e-jobs](./e2e-jobs.png)

In the above diagram, each box is a GitHub Job. The arrows show the order in which the jobs are run. Essentially, each infrastructure step is run in parallel, and then the operator is installed and tested on each infrastructure. Infrastructure refers to the AKS cluster and the Azure resources needed for testing.

E2e can be run in the same way locally but typically only one kind of infrastructure will be chosen to be run locally. The separation of each major phase will be the same.

### Tests

The tests running on each infrastructure must be tested against a number of different scenarios. The major configuration option is the Operator Config which defines things like number of dns zones. Another key piece is that tests must test both upgrade and clean-deploy scenarios for the operator.

Each test defines a matrix of options it will run against including compatible operator versions and operator configs. Then when running tests a testing order is defined where each test with the same operator version and operator config run in parallel. Operator version is incremented appropriately to simulate an upgrade scenario.

For example, we might have the following tests

| Name | Versions | Public Dns Zones | Private Dns Zones |
|--------|---------------|------------------|-------------------|
| Test 1 | Latest, 0.0.3 | One, Multiple | One |
| Test 2 | Latest, 0.0.3 | One | One |

The testing order would be calculated as something like this.

1. Test 1 and 2, 0.0.3, One Public, One Private
2. Test 1, 0.0.3, Multiple Public, One Private
3. Test 1 and 2, Latest, One Public, One Private **(upgrade scenario)**
4. Test 1, Latest, Multiple Public, One Private **(upgrade scenario)**
5. Test 1 and 2, Latest, One Public, One Private **(fresh deploy scenario)**
6. Test 1, Latest, Multiple Public, One Private **(fresh deploy scenario)**

Each row represents the tests and operator configuration that is run in parallel. We wait for tests to finish running for an operator configuration before testing the next configuration.

## Adding new scenarios

Infrastructures are defined in [/testing/e2e/infra/infras.go](../testing/e2e/infra/infras.go). Add any new AKS cluster configurations here.

Tests are defined in [/testing/e2e/suites/](../testing/e2e/suites/). Add any new tests here. [This](../testing/e2e/suites/basic.go) is a good reference for defining a test. Be sure to add any new suites to the [all function](../testing/e2e/suites/all.go) so that they are run.

## GitHub Runner

todo: will fill in details when I add GitHub workflows to run new e2e

## Local E2E

Typically, when testing changes locally it's overkill to test changes on a wide variety of infrastructures, so you will most often filter down to a single infrastructure when testing locally.

Run e2e tests with the following commands.

```bash
go run ./main.go infra --subscription=<subscriptionId> --tenant=<tenantId> --names="basic cluster" # provisions the infrastructure and saves it to local config file
go run ./main.go deploy # deploys the testing job to the cluster and exits based on job status. also uploads logs to local file
```

You can replace `basic cluster` with the name of any infrastructure defined in [/testing/e2e/infra/infras.go](../testing/e2e/infra/infras.go).
14 changes: 11 additions & 3 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ import (
"flag"
"fmt"
"strings"
"time"

"github.com/Azure/go-autorest/autorest/azure"
)

const (
// DefaultNs is the default namespace for the resources deployed by this operator
DefaultNs = "app-routing-system"
PublicZoneType = "dnszones"
PrivateZoneType = "privatednszones"
DefaultNs = "app-routing-system"
PublicZoneType = "dnszones"
PrivateZoneType = "privatednszones"
defaultDnsSyncInterval = 3 * time.Minute
)

var Flags = &Config{}
Expand All @@ -39,6 +41,7 @@ func init() {
flag.StringVar(&Flags.ProbeAddr, "probe-addr", "0.0.0.0:8080", "address to serve readiness/liveness probes on")
flag.StringVar(&Flags.OperatorDeployment, "operator-deployment", "app-routing-operator", "name of the operator's k8s deployment")
flag.StringVar(&Flags.ClusterUid, "cluster-uid", "", "unique identifier of the cluster the add-on belongs to")
flag.DurationVar(&Flags.DnsSyncInterval, "dns-sync-interval", defaultDnsSyncInterval, "interval at which to sync DNS records")
}

type DnsZoneConfig struct {
Expand All @@ -60,6 +63,7 @@ type Config struct {
DisableOSM bool
OperatorDeployment string
ClusterUid string
DnsSyncInterval time.Duration
}

func (c *Config) Validate() error {
Expand Down Expand Up @@ -98,6 +102,10 @@ func (c *Config) Validate() error {
}
}

if c.DnsSyncInterval <= 0 {
c.DnsSyncInterval = defaultDnsSyncInterval
}

return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/manifests/external_dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func newExternalDNSDeployment(conf *config.Config, externalDnsConfig *ExternalDn
Args: append([]string{
"--provider=" + externalDnsConfig.Provider.String(),
"--source=ingress",
"--interval=3m0s",
"--interval=" + conf.DnsSyncInterval.String(),
"--txt-owner-id=" + conf.ClusterUid,
}, domainFilters...),
VolumeMounts: []corev1.VolumeMount{{
Expand Down
18 changes: 15 additions & 3 deletions pkg/manifests/external_dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package manifests
import (
"path"
"testing"
"time"

"github.com/Azure/aks-app-routing-operator/pkg/config"
appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -44,7 +45,7 @@ var (
}{
{
Name: "full",
Conf: &config.Config{NS: "test-namespace", ClusterUid: clusterUid},
Conf: &config.Config{NS: "test-namespace", ClusterUid: clusterUid, DnsSyncInterval: time.Minute * 3},
Deploy: &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: "test-operator-deploy",
Expand All @@ -55,12 +56,12 @@ var (
},
{
Name: "no-ownership",
Conf: &config.Config{NS: "test-namespace", ClusterUid: clusterUid},
Conf: &config.Config{NS: "test-namespace", ClusterUid: clusterUid, DnsSyncInterval: time.Minute * 3},
DnsConfigs: []*ExternalDnsConfig{publicDnsConfig},
},
{
Name: "private",
Conf: &config.Config{NS: "test-namespace", ClusterUid: clusterUid},
Conf: &config.Config{NS: "test-namespace", ClusterUid: clusterUid, DnsSyncInterval: time.Minute * 3},
Deploy: &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: "test-operator-deploy",
Expand All @@ -69,6 +70,17 @@ var (
},
DnsConfigs: []*ExternalDnsConfig{privateDnsConfig},
},
{
Name: "short-sync-interval",
Conf: &config.Config{NS: "test-namespace", ClusterUid: clusterUid, DnsSyncInterval: time.Second * 10},
Deploy: &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: "test-operator-deploy",
UID: "test-operator-deploy-uid",
},
},
DnsConfigs: []*ExternalDnsConfig{publicDnsConfig, privateDnsConfig},
},
}
)

Expand Down
Loading