Skip to content
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
10 changes: 5 additions & 5 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,10 @@ go-test:
COPY --dir +envtest-setup/envtest /usr/local/kubebuilder/bin
# a bit dirty but preload the cache with the images we use in IT (found in functions.yaml)
WITH DOCKER \
--pull xpkg.upbound.io/crossplane-contrib/function-go-templating:v0.11.0 \
--pull xpkg.upbound.io/crossplane-contrib/function-auto-ready:v0.4.2 \
--pull xpkg.upbound.io/crossplane-contrib/function-environment-configs:v0.4.0 \
--pull xpkg.upbound.io/crossplane-contrib/function-extra-resources:v0.1.0
--pull xpkg.crossplane.io/crossplane-contrib/function-go-templating:v0.11.0 \
--pull xpkg.crossplane.io/crossplane-contrib/function-auto-ready:v0.4.2 \
--pull xpkg.crossplane.io/crossplane-contrib/function-environment-configs:v0.4.0 \
--pull xpkg.crossplane.io/crossplane-contrib/function-extra-resources:v0.2.0
# this is silly, but we put these files into the default KUBEBUILDER_ASSETS location, because if we set
# KUBEBUILDER_ASSETS on `go test` to the artifact path, which is perhaps more intuitive, the syntax highlighting
# in intellij breaks due to the word BUILD in all caps.
Expand Down Expand Up @@ -340,7 +340,7 @@ ci-artifacts:
BUILD +multiplatform-build \
--CROSSPLANE_REPO=index.docker.io/crossplane-contrib/crossplane-diff \
--CROSSPLANE_REPO=ghcr.io/crossplane-contrib/crossplane-diff \
--CROSSPLANE_REPO=xpkg.upbound.io/crossplane-contrib/crossplane-diff
--CROSSPLANE_REPO=xpkg.crossplane.io/crossplane-contrib/crossplane-diff

# ci-codeql-setup sets up CodeQL for the ci-codeql target.
ci-codeql-setup:
Expand Down
46 changes: 46 additions & 0 deletions cmd/diff/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package main

import (
"context"
"os"
"os/exec"
"strings"
"testing"
"time"
)

// TestMain runs before all tests and cleans up after all tests complete.
func TestMain(m *testing.M) {
// Run all tests
exitCode := m.Run()

// Clean up orphaned function containers after tests complete
cleanupFunctionContainers()

// Exit with the test suite's exit code
os.Exit(exitCode)
}

// cleanupFunctionContainers removes the named function containers used by integration tests.
func cleanupFunctionContainers() {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

// Use exec.CommandContext to run docker command
cmd := exec.CommandContext(ctx, "docker", "ps", "-a", "-q", "--filter", "name=-it$")
output, err := cmd.Output()
if err != nil {
// Docker might not be available or no containers found - that's okay
return
}

containerIDs := strings.Fields(string(output))
if len(containerIDs) == 0 {
return
}

// Remove the containers
args := append([]string{"rm", "-f"}, containerIDs...)
cleanupCmd := exec.CommandContext(ctx, "docker", args...)
_ = cleanupCmd.Run() // Ignore errors during cleanup
}
28 changes: 24 additions & 4 deletions cmd/diff/testdata/comp/resources/functions.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,49 @@
---
# TODO: when updating these, ensure you also update the list of pulled images in Earthfile/go-test
#
# Named Docker containers for performance optimization in integration tests.
# The 'runtime-docker-name' annotation enables container reuse across multiple test cases.
# The 'runtime-docker-cleanup: Orphan' annotation leaves containers running after render completes,
# allowing subsequent tests to reuse them instead of creating new ones.
#
# IMPORTANT: These containers will persist after test runs. Clean them up manually with:
# docker rm -f $(docker ps -a -q --filter "name=function-*-it")
apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
name: function-go-templating
annotations:
render.crossplane.io/runtime-docker-name: "function-go-templating-v0.11.0-it"
render.crossplane.io/runtime-docker-cleanup: "Orphan"
spec:
package: xpkg.upbound.io/crossplane-contrib/function-go-templating:v0.11.0
package: xpkg.crossplane.io/crossplane-contrib/function-go-templating:v0.11.0
---
apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
name: function-auto-ready
annotations:
render.crossplane.io/runtime-docker-name: "function-auto-ready-v0.4.2-it"
render.crossplane.io/runtime-docker-cleanup: "Orphan"
spec:
package: xpkg.upbound.io/crossplane-contrib/function-auto-ready:v0.4.2
package: xpkg.crossplane.io/crossplane-contrib/function-auto-ready:v0.4.2
---
apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
name: function-environment-configs
annotations:
render.crossplane.io/runtime-docker-name: "function-environment-configs-v0.4.0-it"
render.crossplane.io/runtime-docker-cleanup: "Orphan"
spec:
package: xpkg.upbound.io/crossplane-contrib/function-environment-configs:v0.4.0
package: xpkg.crossplane.io/crossplane-contrib/function-environment-configs:v0.4.0
---
apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
name: function-extra-resources
annotations:
render.crossplane.io/runtime-docker-name: "function-extra-resources-v0.2.0-it"
render.crossplane.io/runtime-docker-cleanup: "Orphan"
spec:
package: xpkg.upbound.io/crossplane-contrib/function-extra-resources:v0.1.0
package: xpkg.crossplane.io/crossplane-contrib/function-extra-resources:v0.2.0
28 changes: 24 additions & 4 deletions cmd/diff/testdata/diff/resources/functions.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,49 @@
---
# TODO: when updating these, ensure you also update the list of pulled images in Earthfile/go-test
#
# Named Docker containers for performance optimization in integration tests.
# The 'runtime-docker-name' annotation enables container reuse across multiple test cases.
# The 'runtime-docker-cleanup: Orphan' annotation leaves containers running after render completes,
# allowing subsequent tests to reuse them instead of creating new ones.
#
# IMPORTANT: These containers will persist after test runs. Clean them up manually with:
# docker rm -f $(docker ps -a -q --filter "name=function-*-it")
apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
name: function-go-templating
annotations:
render.crossplane.io/runtime-docker-name: "function-go-templating-v0.11.0-it"
render.crossplane.io/runtime-docker-cleanup: "Orphan"
spec:
package: xpkg.upbound.io/crossplane-contrib/function-go-templating:v0.11.0
package: xpkg.crossplane.io/crossplane-contrib/function-go-templating:v0.11.0
---
apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
name: function-auto-ready
annotations:
render.crossplane.io/runtime-docker-name: "function-auto-ready-v0.4.2-it"
render.crossplane.io/runtime-docker-cleanup: "Orphan"
spec:
package: xpkg.upbound.io/crossplane-contrib/function-auto-ready:v0.4.2
package: xpkg.crossplane.io/crossplane-contrib/function-auto-ready:v0.4.2
---
apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
name: function-environment-configs
annotations:
render.crossplane.io/runtime-docker-name: "function-environment-configs-v0.4.0-it"
render.crossplane.io/runtime-docker-cleanup: "Orphan"
spec:
package: xpkg.upbound.io/crossplane-contrib/function-environment-configs:v0.4.0
package: xpkg.crossplane.io/crossplane-contrib/function-environment-configs:v0.4.0
---
apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
name: function-extra-resources
annotations:
render.crossplane.io/runtime-docker-name: "function-extra-resources-v0.2.0-it"
render.crossplane.io/runtime-docker-cleanup: "Orphan"
spec:
package: xpkg.upbound.io/crossplane-contrib/function-extra-resources:v0.1.0
package: xpkg.crossplane.io/crossplane-contrib/function-extra-resources:v0.2.0
Loading