-
Notifications
You must be signed in to change notification settings - Fork 69
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
Add native registry login tests for EKS, AKS and GKE #275
Conversation
7804f22
to
ce83335
Compare
ce83335
to
640d2d9
Compare
Posting some results to provide an idea of what it looks like when run. With # AWS
export AWS_ACCESS_KEY_ID=<redacted>
export AWS_SECRET_ACCESS_KEY=<redacted>
export AWS_REGION=us-east-2
# Azure
export TF_VAR_azure_location=eastus
# GCP
export TF_VAR_gcp_project_id=<redacted>
# export TF_VAR_gcp_region=us-central1
# export TF_VAR_gcp_zone=us-central1-c
# Leave GCR region empty to use gcr.io. Else set it to `us`, `eu` or `asia`.
# export TF_VAR_gcr_region= and aws: $ make test-aws
make test PROVIDER_ARG="-provider aws"
make[1]: Entering directory '/home/go/src/github.com/fluxcd/image-reflector-controller/tests/integration'
cp kustomization.yaml build/flux
cd build/flux && kustomize edit set image fluxcd/image-reflector-controller=fluxcd/image-reflector-controller
kustomize build build/flux > build/flux.yaml
go test -timeout 30m -v ./... -provider aws
2022/06/23 02:53:59 Terraform binary: /usr/bin/terraform
2022/06/23 02:53:59 Init Terraform
2022/06/23 02:54:05 Checking for an empty Terraform state
2022/06/23 02:54:07 Applying Terraform
2022/06/23 03:08:34 pushing test image z.dkr.ecr.us-east-2.amazonaws.com/flux-test-repo-peaceful-ghost:v0.1.0
2022/06/23 03:08:38 pushing test image z.dkr.ecr.us-east-2.amazonaws.com/flux-test-repo-peaceful-ghost:v0.1.2
2022/06/23 03:08:41 pushing test image z.dkr.ecr.us-east-2.amazonaws.com/flux-test-repo-peaceful-ghost:v0.1.3
2022/06/23 03:08:44 pushing test image z.dkr.ecr.us-east-2.amazonaws.com/flux-test-repo-peaceful-ghost:v0.1.4
2022/06/23 03:08:47 Installing flux
=== RUN TestImageRepositoryScan
=== RUN TestImageRepositoryScan/ecr
--- PASS: TestImageRepositoryScan (2.01s)
--- PASS: TestImageRepositoryScan/ecr (2.01s)
PASS
2022/06/23 03:09:20 Destroying environment...
ok github.com/fluxcd/image-reflector-controller/tests/integration 1592.611s
make[1]: Leaving directory '/home/go/src/github.com/fluxcd/image-reflector-controller/tests/integration' azure: $ make test-azure
make test PROVIDER_ARG="-provider azure"
make[1]: Entering directory '/home/go/src/github.com/fluxcd/image-reflector-controller/tests/integration'
cp kustomization.yaml build/flux
cd build/flux && kustomize edit set image fluxcd/image-reflector-controller=fluxcd/image-reflector-controller
kustomize build build/flux > build/flux.yaml
go test -timeout 30m -v ./... -provider azure
2022/06/23 03:23:50 Terraform binary: /usr/bin/terraform
2022/06/23 03:23:50 Init Terraform
2022/06/23 03:23:52 Checking for an empty Terraform state
2022/06/23 03:23:52 Applying Terraform
2022/06/23 03:29:34 pushing test image fluxtestrepomovingotick.azurecr.io/vynz8:v0.1.0
2022/06/23 03:29:38 pushing test image fluxtestrepomovingotick.azurecr.io/vynz8:v0.1.2
2022/06/23 03:29:40 pushing test image fluxtestrepomovingotick.azurecr.io/vynz8:v0.1.3
2022/06/23 03:29:42 pushing test image fluxtestrepomovingotick.azurecr.io/vynz8:v0.1.4
2022/06/23 03:29:45 Installing flux
=== RUN TestImageRepositoryScan
=== RUN TestImageRepositoryScan/acr
--- PASS: TestImageRepositoryScan (3.36s)
--- PASS: TestImageRepositoryScan/acr (3.36s)
PASS
2022/06/23 03:30:16 Destroying environment...
ok github.com/fluxcd/image-reflector-controller/tests/integration 749.433s
make[1]: Leaving directory '/home/go/src/github.com/fluxcd/image-reflector-controller/tests/integration' gcp: $ make test-gcp
make test PROVIDER_ARG="-provider gcp"
make[1]: Entering directory '/home/go/src/github.com/fluxcd/image-reflector-controller/tests/integration'
cp kustomization.yaml build/flux
cd build/flux && kustomize edit set image fluxcd/image-reflector-controller=fluxcd/image-reflector-controller
kustomize build build/flux > build/flux.yaml
go test -timeout 30m -v ./... -provider gcp
2022/06/23 03:39:18 Terraform binary: /usr/bin/terraform
2022/06/23 03:39:18 Init Terraform
2022/06/23 03:39:22 Checking for an empty Terraform state
2022/06/23 03:39:23 Applying Terraform
2022/06/23 03:44:37 pushing test image gcr.io/z/ik9ar:v0.1.0
2022/06/23 03:44:46 pushing test image gcr.io/z/ik9ar:v0.1.2
2022/06/23 03:44:54 pushing test image gcr.io/z/ik9ar:v0.1.3
2022/06/23 03:45:02 pushing test image gcr.io/z/ik9ar:v0.1.4
2022/06/23 03:45:10 pushing test image us-central1-docker.pkg.dev/z/flux-test-repo-helpful-kangaroo/8y697:v0.1.0
2022/06/23 03:45:19 pushing test image us-central1-docker.pkg.dev/z/flux-test-repo-helpful-kangaroo/8y697:v0.1.2
2022/06/23 03:45:26 pushing test image us-central1-docker.pkg.dev/z/flux-test-repo-helpful-kangaroo/8y697:v0.1.3
2022/06/23 03:45:32 pushing test image us-central1-docker.pkg.dev/z/flux-test-repo-helpful-kangaroo/8y697:v0.1.4
2022/06/23 03:45:38 Installing flux
=== RUN TestImageRepositoryScan
=== RUN TestImageRepositoryScan/gcr
=== RUN TestImageRepositoryScan/artifact_registry
--- PASS: TestImageRepositoryScan (9.11s)
--- PASS: TestImageRepositoryScan/gcr (8.29s)
--- PASS: TestImageRepositoryScan/artifact_registry (0.82s)
PASS
2022/06/23 03:46:17 Destroying environment...
ok github.com/fluxcd/image-reflector-controller/tests/integration 568.476s
make[1]: Leaving directory '/home/go/src/github.com/fluxcd/image-reflector-controller/tests/integration' |
640d2d9
to
780bf84
Compare
780bf84
to
3a2b472
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small question, otherwise LGTM.
This looks really good but I think some of these things would be good to share with the Azure E2E tests. Maybe we should move some of the packages to pkg instead? |
@phillebaba yes, that's the plan after getting these changes reviewed, accepted and merged here initially. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job @darkowlzz!
LGTM!
role_based_access_control_enabled = true | ||
network_profile { | ||
network_plugin = "kubenet" | ||
network_policy = "calico" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason for choosing kubenet and calico for Azure CNI? Don't think it really matters but the default value when creating and AKS cluster is to use Azure CNI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Azure CNI does not work with Flux network policies, using Calico matches flux2 e2e tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small NIT but otherwise great!
tftestenv is similar to testenv but uses terraform to create test environment. It provides helpers to run terraform apply and destroy in the test context and a few other helpers for executing commands. Signed-off-by: Sunny <darkowlzz@protonmail.com>
Use tftestenv to create tests similar to the controller tests but with EKS cluster provisioned using terraform. The test setup is written similar to the usual controller test suite_test.go, providing flexibility in the test setup and execution. The structure tries to keep the infrastructure code separate from the test code such that the infrastructure provisioning tool can be easily replaced, without the need to change the actual tests. The go tests are also written similar to the usual controller tests, with a kube client from the tftestenv environment global variable. Terraform is automatically downloaded using the terraform-exec package. The test container images are generated using the go-containerregistry package and pushed to the test container image repository. Co-authored-by: Somtochi Onyekwere <somtochionyekwere@gmail.com> Signed-off-by: Sunny <darkowlzz@protonmail.com>
Add azure as a new provider to provision infrastructure and test against. Unlike aws, azurerm terraform provider doesn't provide a way to natively configure the region/location. To work around that, a terraform variable `azure_location` is used, which can be configured by environment variable `TF_VAR_azure_location`, added in .env.sample. Unlike AWS ECR, Azure ACR requires creating a new container registry which creates dynamic repositories on push, similar to docker hub. The registry login code handles that and sets randomly generated repository names. Co-authored-by: Somtochi Onyekwere <somtochionyekwere@gmail.com> Signed-off-by: Sunny <darkowlzz@protonmail.com>
Add GCP as a new provider to provision infrastructure and test against. GCP has Google Container Registry and Artifact Registry for storing images. The test setup provisions and pushes images to both and tests them both. The GKE node pool is configured with OAuth Scope to provide full access to the GCP APIs. Workload identity is not used to avoid increasing the complixity of the setup. Co-authored-by: Somtochi Onyekwere <somtochionyekwere@gmail.com> Signed-off-by: Sunny <darkowlzz@protonmail.com>
Rebased and verified that it works with go 1.18. |
It introduces a new package
tftestenv
. It is similar to testenv but usesterraform to create test environment. It provides helpers to run terraform
apply and destroy in the test context.
tftestenv
is used to create tests similar to the controller tests but withcloud provider managed cluster provisioned using terraform. The test
setup is written similar to the usual controller test suite_test.go,
providing flexibility in the test setup and execution. The structure tries
to keep the infrastructure code separate from the test code such that
the infrastructure provisioning tool can be easily replaced, without the
need to change the actual tests.
The go tests are also written similar to the usual controller tests,
with a kube client from the tftestenv environment global variable.
Terraform is automatically downloaded using the terraform-exec package.
The test container images are generated using the go-containerregistry
package and pushed to the test container image repository.
tests/integration/README.md
contains more details about the test setup and workflow.The terraform configurations for EKS is based on https://github.com/terraform-aws-modules/terraform-aws-eks/tree/6bb73bbdd469797cb067e9aa22ce2f31a7fb22be/examples/self_managed_node_group .
The terraform configurations for AKS is based on https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/kubernetes_cluster .
The terraform configurations for GKE is based on the official GKE terraform provider examples https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_cluster with Terraform Kubernetes Engine Auth Module to be able to easily retrieve the kubeconfig. Both GCR and Artifact Registry are tested.
Average test duration including provisioning and cleanup time:
We may be able to optimize some configurations to bring down the time of EKS and AKS in the future.
Part of #264.