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

tests/int: IAM CI setup docs & exit code propagation #423

Merged
merged 2 commits into from
Jul 21, 2023
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
98 changes: 90 additions & 8 deletions tests/integration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,48 @@ the tests:
- `Microsoft.ContainerRegistry/*`
- `Microsoft.ContainerService/*`

#### IAM and CI setup

To create the necessary IAM role with all the permissions, set up CI secrets and
variables using
[azure-gh-actions](https://github.com/fluxcd/test-infra/tree/main/tf-modules/azure/github-actions)
use the terraform configuration below. Please make sure all the requirements of
azure-gh-actions are followed before running it.

```hcl
provider "github" {
owner = "fluxcd"
}

module "azure_gh_actions" {
source = "git::https://github.com/fluxcd/test-infra.git//tf-modules/azure/github-actions"

azure_owners = ["owner-id-1", "owner-id-2"]
azure_app_name = "irc-e2e"
azure_app_description = "irc e2e"
azure_permissions = [
"Microsoft.Kubernetes/*",
"Microsoft.Resources/*",
"Microsoft.Authorization/roleAssignments/Read",
"Microsoft.Authorization/roleAssignments/Write",
"Microsoft.Authorization/roleAssignments/Delete",
"Microsoft.ContainerRegistry/*",
"Microsoft.ContainerService/*"
]
azure_location = "eastus"

github_project = "image-reflector-controller"

github_secret_client_id_name = "IRC_E2E_AZ_ARM_CLIENT_ID"
github_secret_client_secret_name = "IRC_E2E_AZ_ARM_CLIENT_SECRET"
github_secret_subscription_id_name = "IRC_E2E_AZ_ARM_SUBSCRIPTION_ID"
github_secret_tenant_id_name = "IRC_E2E_AZ_ARM_TENANT_ID"
}
```

**NOTE:** The environment variables used above are for the GitHub workflow that
runs the tests. Change the variable names if needed accordingly.

### Google Cloud Platform

- GCP account with project and GKE, GCR and Artifact Registry services enabled
Expand Down Expand Up @@ -90,14 +132,54 @@ $ gcrgc gcr.io/<project-name>

Following roles are needed for provisioning the infrastructure and running the
tests:
- `Artifact Registry Administrator`
- `Compute Instance Admin (v1)`
- `Compute Storage Admin`
- `Kubernetes Engine Admin`
- `Service Account Admin`
- `Service Account Token Creator`
- `Service Account User`
- `Storage Admin`
- Artifact Registry Administrator - `roles/artifactregistry.admin`
- Compute Instance Admin (v1) - `roles/compute.instanceAdmin.v1`
- Compute Storage Admin - `roles/compute.storageAdmin`
- Kubernetes Engine Admin - `roles/container.admin`
- Service Account Admin - `roles/iam.serviceAccountAdmin`
- Service Account Token Creator - `roles/iam.serviceAccountTokenCreator`
- Service Account User - `roles/iam.serviceAccountUser`
- Storage Admin - `roles/storage.admin`

#### IAM and CI setup

To create the necessary IAM role with all the permissions, set up CI secrets and
variables using
[gcp-gh-actions](https://github.com/fluxcd/test-infra/tree/main/tf-modules/gcp/github-actions)
use the terraform configuration below. Please make sure all the requirements of
gcp-gh-actions are followed before running it.

```hcl
provider "google" {}

provider "github" {
owner = "fluxcd"
}

module "gcp_gh_actions" {
source = "git::https://github.com/fluxcd/test-infra.git//tf-modules/gcp/github-actions"

gcp_service_account_id = "irc-e2e"
gcp_service_account_name = "irc-e2e"
gcp_roles = [
"roles/artifactregistry.admin",
"roles/compute.instanceAdmin.v1",
"roles/compute.storageAdmin",
"roles/container.admin",
"roles/iam.serviceAccountAdmin",
"roles/iam.serviceAccountTokenCreator",
"roles/iam.serviceAccountUser",
"roles/storage.admin"
]

github_project = "image-reflector-controller"

github_secret_credentials_name = "IRC_E2E_GOOGLE_CREDENTIALS"
}
```

**NOTE:** The environment variables used above are for the GitHub workflow that
runs the tests. Change the variable names if needed accordingly.

## Test setup

Expand Down
9 changes: 3 additions & 6 deletions tests/integration/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,11 @@ func TestMain(m *testing.M) {
log.Printf("Failed to stop environment: %v", err)
}

// Calling exit on panic prevents logging of panic error.
// Exit only on normal return. Explicitly detect panic and log the error
// on panic.
if err := recover(); err == nil {
os.Exit(exitCode)
} else {
// Log the panic error before exit to surface the cause of panic.
if err := recover(); err != nil {
log.Printf("panic: %v", err)
}
os.Exit(exitCode)
}()

// Get terraform state output.
Expand Down
1 change: 1 addition & 0 deletions tests/integration/terraform/azure/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module "acr" {
location = var.azure_location
aks_principal_id = [module.aks.principal_id]
resource_group = module.aks.resource_group
admin_enabled = true
tags = var.tags

depends_on = [module.aks]
Expand Down