Skip to content

Commit

Permalink
chore: migrate tests to imagetest (#2318)
Browse files Browse the repository at this point in the history
* chore(argo): migrate to imagetest

Signed-off-by: Mauren Berti <[email protected]>

* chore(atlantis): migrate to imagetest

Signed-off-by: Mauren Berti <[email protected]>

* chore(aws-for-fluent-bit): migrate to imagetest

Signed-off-by: Mauren Berti <[email protected]>

* chore(bank-vaults): migrate to imagetest

Signed-off-by: Mauren Berti <[email protected]>

---------

Signed-off-by: Mauren Berti <[email protected]>
  • Loading branch information
stormqueen1990 authored Mar 6, 2024
1 parent 9837a8d commit 376d0b5
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 118 deletions.
12 changes: 6 additions & 6 deletions images/argo/tests/check-argo-workflow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -o errexit -o nounset -o errtrace -o pipefail -x

kubectl -n argo-workflows apply -f - <<EOF
cat <<EOF | kubectl --namespace argo-workflows apply --filename -
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
Expand All @@ -17,9 +17,9 @@ spec:
args: [ "hello world" ]
EOF

sleep 3
kubectl wait --for=condition=Completed workflows/hello \
--namespace argo-workflows \
--timeout 2m

kubectl -n argo-workflows wait workflows/hello --for condition=Completed --timeout 2m

kubectl logs -n argo-workflows pod/hello
trap "kubectl -n argo-workflows delete workflows/hello" EXIT
kubectl logs --namespace argo-workflows pod/hello
trap "kubectl --namespace argo-workflows delete workflows/hello" EXIT
112 changes: 64 additions & 48 deletions images/argo/tests/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
oci = { source = "chainguard-dev/oci" }
helm = { source = "hashicorp/helm" }
oci = { source = "chainguard-dev/oci" }
imagetest = { source = "chainguard-dev/imagetest" }
}
}

Expand All @@ -14,68 +14,84 @@ variable "digests" {
})
}



data "oci_string" "ref" {
for_each = var.digests
input = each.value
}

data "imagetest_inventory" "this" {}

resource "imagetest_harness_k3s" "this" {
name = "argo"
inventory = data.imagetest_inventory.this

resource "helm_release" "argo" {
name = "argo-workflows"
sandbox = {
mounts = [
{
source = path.module
destination = "/tests"
}
]
}
}

repository = "https://argoproj.github.io/argo-helm"
chart = "argo-workflows"
module "helm" {
source = "../../../tflib/imagetest/helm"

namespace = "argo-workflows"
create_namespace = true
name = "argo-workflows"
namespace = "argo-workflows"
chart = "argo-workflows"
repo = "https://argoproj.github.io/argo-helm"

values = [
jsonencode({
values = {
image = {
tag = ""
}
server = {
image = {
tag = ""
registry = join("", [data.oci_string.ref["cli"].registry, ""])
repository = data.oci_string.ref["cli"].repo
tag = data.oci_string.ref["cli"].pseudo_tag

}
server = {
executor = {
image = {
registry = join("", [data.oci_string.ref["cli"].registry, ""])
repository = data.oci_string.ref["cli"].repo
tag = data.oci_string.ref["cli"].pseudo_tag

registry = join("", [data.oci_string.ref["exec"].registry, ""])
repository = data.oci_string.ref["exec"].repo
tag = data.oci_string.ref["exec"].pseudo_tag
}
executor = {
image = {
registry = join("", [data.oci_string.ref["exec"].registry, ""])
repository = data.oci_string.ref["exec"].repo
tag = data.oci_string.ref["exec"].pseudo_tag
}
}
controller = {
image = {
registry = join("", [data.oci_string.ref["worfkflowcontroller"].registry, ""])
repository = data.oci_string.ref["worfkflowcontroller"].repo
tag = data.oci_string.ref["worfkflowcontroller"].pseudo_tag
}
}
controller = {
image = {
registry = join("", [data.oci_string.ref["worfkflowcontroller"].registry, ""])
repository = data.oci_string.ref["worfkflowcontroller"].repo
tag = data.oci_string.ref["worfkflowcontroller"].pseudo_tag
}

}

}),
]
}
}
}

resource "imagetest_feature" "basic" {
harness = imagetest_harness_k3s.this
name = "Basic"
description = "Basic functionality of the argo helm chart."

steps = [
{
name = "Helm install"
cmd = module.helm.install_cmd
},
{
name = "Argo Helm tests"
workdir = "/tests"
cmd = <<EOF
./check-argo-workflow.sh
EOF
},
]

data "oci_exec_test" "check-argo" {
digest = var.digests["cli"] # we are testing the whole helm release digest here is a place holder
script = "./check-argo-workflow.sh"
working_dir = path.module
depends_on = [helm_release.argo]

}

module "helm_cleanup" {
depends_on = [data.oci_exec_test.check-argo]
source = "../../../tflib/helm-cleanup"
name = helm_release.argo.id
namespace = helm_release.argo.namespace
labels = {
type = "k8s"
}
}
79 changes: 42 additions & 37 deletions images/atlantis/tests/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
oci = { source = "chainguard-dev/oci" }
helm = { source = "hashicorp/helm" }
oci = { source = "chainguard-dev/oci" }
imagetest = { source = "chainguard-dev/imagetest" }
}
}

Expand All @@ -11,52 +11,57 @@ variable "digest" {

data "oci_string" "ref" { input = var.digest }

data "oci_exec_test" "version" {
digest = var.digest
script = "docker run --rm $IMAGE_NAME version"
}

data "imagetest_inventory" "this" {}

resource "imagetest_harness_k3s" "this" {
name = "atlantis"
inventory = data.imagetest_inventory.this
}

resource "random_pet" "suffix" {}

resource "helm_release" "atlantis" {
name = "runatlantis-${random_pet.suffix.id}"
namespace = "runatlantis-system-${random_pet.suffix.id}"
repository = "https://runatlantis.github.io/helm-charts"
chart = "atlantis"
create_namespace = true
timeout = 600
module "helm" {
source = "../../../tflib/imagetest/helm"

name = "runatlantis-${random_pet.suffix.id}"
namespace = "runatlantis-system-${random_pet.suffix.id}"
repo = "https://runatlantis.github.io/helm-charts"
chart = "atlantis"
timeout = "600s"

values = [jsonencode({
values = {
image = {
repository = data.oci_string.ref.registry_repo
tag = data.oci_string.ref.pseudo_tag
pullPolicy = "Always"
}
})]

set {
name = "github.user"
value = "not_used_tacocat_user"
github = {
user = "not_used_tacocat_user"
token = "not_used_tacocat_token"
secret = "not_used_tacocat_shhhh"
}
orgAllowlist = "not_used_tacocat_user"
}
}

set {
name = "github.token"
value = "not_used_tacocat_token"
}
resource "imagetest_feature" "basic" {
harness = imagetest_harness_k3s.this
name = "basic"
description = "Basic functionality of Atlantis installed in a Kubernetes cluster"

set {
name = "github.secret"
value = "not_used_tacocat_shhhh"
}
steps = [
{
name = "Helm install"
cmd = module.helm.install_cmd
}
]

set {
name = "orgAllowlist"
value = "not_used_tacocat_user"
labels = {
type = "k8s",
}
}

module "helm_cleanup_atlantis" {
source = "../../../tflib/helm-cleanup"
name = helm_release.atlantis.id
namespace = helm_release.atlantis.namespace
}

data "oci_exec_test" "version" {
digest = var.digest
script = "docker run --rm $IMAGE_NAME version"
}
42 changes: 31 additions & 11 deletions images/aws-for-fluent-bit/tests/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
oci = { source = "chainguard-dev/oci" }
helm = { source = "hashicorp/helm" }
oci = { source = "chainguard-dev/oci" }
imagetest = { source = "chainguard-dev/imagetest" }
}
}

Expand All @@ -16,23 +16,43 @@ data "oci_exec_test" "startup" {
script = "${path.module}/startup.sh"
}

data "imagetest_inventory" "this" {}

resource "imagetest_harness_k3s" "this" {
name = "aws-for-fluent-bit"
inventory = data.imagetest_inventory.this
}

resource "random_pet" "suffix" {}

resource "helm_release" "fluent-bit" {
name = "fluent-bit-${random_pet.suffix.id}"
module "helm" {
source = "../../../tflib/imagetest/helm"

repository = "https://fluent.github.io/helm-charts"
chart = "fluent-bit"
name = "fluent-bit-${random_pet.suffix.id}"
repo = "https://fluent.github.io/helm-charts"
chart = "fluent-bit"

values = [jsonencode({
values = {
image = {
repository = data.oci_string.ref.registry_repo
tag = data.oci_string.ref.pseudo_tag
}
})]
}
}

module "helm_cleanup" {
source = "../../../tflib/helm-cleanup"
name = helm_release.fluent-bit.id
resource "imagetest_feature" "basic" {
harness = imagetest_harness_k3s.this
name = "basic"
description = "Basic functionality of AWS for Fluent Bit installed in a Kubernetes cluster"

steps = [
{
name = "Helm install"
cmd = module.helm.install_cmd
}
]

labels = {
type = "k8s",
}
}
Loading

0 comments on commit 376d0b5

Please sign in to comment.