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

Run Agones tests in CI #551

Merged
merged 3 commits into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion agones/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ module "agones_cluster" {
module "helm_agones" {
source = "git::https://github.com/googleforgames/agones.git//install/terraform/modules/helm3/?ref=release-1.24.0"

agones_version = "1.23.0"
agones_version = "1.24.0"
values_file = ""
chart = "agones"
host = module.agones_cluster.host
Expand Down
22 changes: 19 additions & 3 deletions agones/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ use std::{
time::{SystemTime, UNIX_EPOCH},
};

use k8s_openapi::{api::core::v1::Namespace, apimachinery::pkg::apis::meta::v1::ObjectMeta};
use k8s_openapi::{
api::core::v1::Namespace, apimachinery::pkg::apis::meta::v1::ObjectMeta, chrono,
};
use kube::{
api::{DeleteParams, ListParams, PostParams},
Api, ResourceExt,
Expand All @@ -33,6 +35,7 @@ mod pod;
static CLIENT: OnceCell<Client> = OnceCell::const_new();
#[allow(dead_code)]
const IMAGE_TAG: &str = "IMAGE_TAG";
const DELETE_DELAY_SECONDS: &str = "DELETE_DELAY_SECONDS";

pub struct Client {
/// The Kubernetes client
Expand Down Expand Up @@ -75,10 +78,23 @@ async fn setup_namespace(client: kube::Client) -> String {
let lp = ListParams::default().labels("owner=quilkin-test");
let nss = namespaces.list(&lp).await.unwrap();
let dp = DeleteParams::default();

let delay = env::var_os(DELETE_DELAY_SECONDS)
.map(|value| chrono::Duration::seconds(value.into_string().unwrap().parse().unwrap()));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: You don't need to use var_os if you're converting to string anyway, and you can flatten the unwraps.

Suggested change
let delay = env::var_os(DELETE_DELAY_SECONDS)
.map(|value| chrono::Duration::seconds(value.into_string().unwrap().parse().unwrap()));
let delay = env::var(DELETE_DELAY_SECONDS)
.as_deref()
.ok()
.and_then(|s| i64::parse(s).ok())
.map(chrono::Duration::seconds);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I swear I never saw env::var() existing before. Totally missed that. Thank you!


for ns in nss {
let name = ns.name();
if let Err(err) = namespaces.delete(name.as_str(), &dp).await {
println!("Failure attempting to deleted namespace: {:?}, {err}", name);

let delete = delay
.and_then(|duration| {
let expiry = ns.creation_timestamp()?.0 + duration;
Some(chrono::Utc::now() > expiry)
})
.unwrap_or(true);
if delete {
if let Err(err) = namespaces.delete(name.as_str(), &dp).await {
println!("Failure attempting to deleted namespace: {:?}, {err}", name);
}
}
}

Expand Down
21 changes: 16 additions & 5 deletions build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ helm_config := ~/.config/helm
helm_cache := ~/.cache/helm

kube_mount_args := -v $(kubeconfig_path):/root/.kube -v $(helm_config):/root/.config/helm -v $(helm_cache):/root/.cache/helm

minikube_args := --network=host -v ~/.minikube:$(HOME)/.minikube
gcloud_mount_args := -v $(build_path)/.config/gcloud:/root/.config/gcloud

# _____ _
# |_ _|_ _ _ __ __ _ ___| |_ ___
Expand Down Expand Up @@ -165,8 +165,12 @@ run-test-agones:

# Convenience target to build and push quilkin images to a repository.
# Use `REPOSITORY` arg to specify the repository to push to.
# USe `SKIP_BUILD_IMAGE` if you want to skip building the image if it has been already built.
# See `build-image` for more details.
push:
ifndef SKIP_BUILD_IMAGE
push: build-image
endif
docker push $(IMAGE_TAG)-debug
docker push $(IMAGE_TAG)

Expand Down Expand Up @@ -196,10 +200,9 @@ docs: ensure-build-image

# Start an interactive shell inside the build image
# Useful for testing, or adhoc cargo, gcloud, kubectl or terraform commands
shell: ensure-kube-dirs ensure-build-image
-mkdir -p $(build_path)/.gcloud
shell: ensure-gcloud-dirs ensure-kube-dirs ensure-build-image
docker run --rm -it $(DOCKER_RUN_ARGS) $(common_rust_args) \
-v $(build_path)/.config/gcloud:/root/.config/gcloud $(kube_mount_args) \
$(gcloud_mount_args) $(kube_mount_args) \
--entrypoint=bash $(BUILD_IMAGE_TAG)

ensure-build-image: ensure-cargo-registry
Expand All @@ -208,6 +211,14 @@ ensure-build-image: ensure-cargo-registry
ensure-cargo-registry:
-mkdir -p $(CARGO_HOME)/registry

ensure-gcloud-dirs:
-mkdir -p $(build_path)/.gcloud

ensure-kube-dirs:
-mkdir -p ~/.config/helm
-mkdir -p ~/.kube
-mkdir -p ~/.kube

ci-gcloud-auth-cluster:
# Internal CI target. Used to authenticate against the integration test cluster.
docker run --rm $(DOCKER_RUN_ARGS) $(common_rust_args) $(kube_mount_args) --network=cloudbuild \
-e "USE_GKE_GCLOUD_AUTH_PLUGIN=True" --entrypoint=gcloud $(BUILD_IMAGE_TAG) container clusters get-credentials agones --zone us-west1-c
45 changes: 35 additions & 10 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,34 @@ steps:
- name: gcr.io/cloud-builders/git
args: [ submodule, update, --init, --recursive ]
id: fetch-git-submodules
waitFor:
- "-"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a comment here explaining this. Maybe this is obvious to people who use cloudbuild, but it's not obvious to me compared to other usages of waitFor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent suggestion - will do.

- name: gcr.io/cloud-builders/docker
args: [ pull, "${_BUILD_IMAGE_TAG}" ]
id: pull-build-image
waitFor:
- "-"
- name: us-docker.pkg.dev/$PROJECT_ID/ci/make-docker
dir: ./build
args:
- BUILD_IMAGE_TAG=${_BUILD_IMAGE_TAG}
- BUILD_IMAGE_ARG=--cache-from ${_BUILD_IMAGE_TAG}
- test-quilkin
id: test-quilkin
waitFor:
- fetch-git-submodules
- pull-build-image
- name: us-docker.pkg.dev/$PROJECT_ID/ci/make-docker
dir: ./build
args:
- BUILD_IMAGE_TAG=${_BUILD_IMAGE_TAG}
- BUILD_IMAGE_ARG=--cache-from ${_BUILD_IMAGE_TAG}
- test-examples
id: test-examples
- name: us-docker.pkg.dev/$PROJECT_ID/ci/make-docker
dir: ./build
args:
- BUILD_IMAGE_TAG=${_BUILD_IMAGE_TAG}
- BUILD_IMAGE_ARG=--cache-from ${_BUILD_IMAGE_TAG}
- test-docs
id: test-docs
- name: us-docker.pkg.dev/$PROJECT_ID/ci/make-docker
dir: ./build
args:
- BUILD_IMAGE_TAG=${_BUILD_IMAGE_TAG}
- BUILD_IMAGE_ARG=--cache-from ${_BUILD_IMAGE_TAG}
- build
id: build
# Run the built images for 5 seconds to make sure that the entrypoint and default config works out of the box
Expand All @@ -53,21 +52,47 @@ steps:
entrypoint: bash
args:
- '-c'
- 'timeout --signal=INT --preserve-status 5s docker run --rm quilkin:$(make version)'
- 'timeout --signal=INT --preserve-status 5s docker run --rm ${_REPOSITORY}quilkin:$(make version)'
id: test-quilkin-debug
waitFor:
- build
- name: gcr.io/cloud-builders/docker
dir: ./build
entrypoint: bash
args:
- '-c'
- 'timeout --signal=INT --preserve-status 5s docker run --rm quilkin:$(make version)-debug'
- 'timeout --signal=INT --preserve-status 5s docker run --rm ${_REPOSITORY}quilkin:$(make version)-debug'
id: test-quilkin-release
waitFor:
- build
- name: us-docker.pkg.dev/$PROJECT_ID/ci/make-docker
dir: ./build
args:
- ci-gcloud-auth-cluster
id: gcloud-auth-cluster
waitFor:
- test-quilkin
- name: us-docker.pkg.dev/$PROJECT_ID/ci/make-docker
dir: ./build
args:
- SKIP_BUILD_IMAGE=1
- DELETE_DELAY_SECONDS=3600
- DOCKER_RUN_ARGS=--network=cloudbuild
- test-agones
id: test-agones
waitFor:
- gcloud-auth-cluster
- build
options:
env:
- "CARGO_HOME=/workspace/.cargo"
- "REPOSITORY=${_REPOSITORY}"
- "BUILD_IMAGE_TAG=${_BUILD_IMAGE_TAG}"
- "BUILD_IMAGE_ARG=--cache-from ${_BUILD_IMAGE_TAG}"
machineType: E2_HIGHCPU_32
dynamic_substitutions: true
timeout: 7200s
substitutions:
_BUILD_IMAGE_TAG: us-docker.pkg.dev/${PROJECT_ID}/ci/build-image
_REPOSITORY: us-docker.pkg.dev/${PROJECT_ID}/ci/
logsBucket: "gs://quilkin-build-logs"