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
22 changes: 0 additions & 22 deletions test/e2e/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import (
"github.com/crossplane/crossplane-runtime/v2/pkg/resource/unstructured/composed"

apiextensionsv1 "github.com/crossplane/crossplane/v2/apis/apiextensions/v1"
pkgv1 "github.com/crossplane/crossplane/v2/apis/pkg/v1"
"github.com/crossplane/crossplane/v2/test/e2e"
"github.com/crossplane/crossplane/v2/test/e2e/config"
"github.com/crossplane/crossplane/v2/test/e2e/funcs"
Expand Down Expand Up @@ -115,7 +114,6 @@ func TestDiffNewResourceV2Cluster(t *testing.T) {
funcs.ApplyResources(e2e.FieldManager, setupPath, "*.yaml"),
funcs.ResourcesCreatedWithin(30*time.Second, setupPath, "*.yaml"),
funcs.ResourcesHaveConditionWithin(1*time.Minute, setupPath, "definition.yaml", apiextensionsv1.WatchingComposite()),
funcs.ResourcesHaveConditionWithin(2*time.Minute, setupPath, "provider.yaml", pkgv1.Healthy(), pkgv1.Active()),
)).
Assess("CanDiffNewResource", func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context {
t.Helper()
Expand Down Expand Up @@ -156,7 +154,6 @@ func TestDiffExistingResourceV2Cluster(t *testing.T) {
)).
WithSetup("PrerequisitesAreReady", funcs.AllOf(
funcs.ResourcesHaveConditionWithin(1*time.Minute, setupPath, "definition.yaml", apiextensionsv1.WatchingComposite()),
funcs.ResourcesHaveConditionWithin(2*time.Minute, setupPath, "provider.yaml", pkgv1.Healthy(), pkgv1.Active()),
)).
WithSetup("CreateExistingXR", funcs.AllOf(
funcs.ApplyResources(e2e.FieldManager, manifests, "existing-xr.yaml"),
Expand Down Expand Up @@ -203,7 +200,6 @@ func TestDiffNewResourceV2Namespaced(t *testing.T) {
)).
WithSetup("PrerequisitesAreReady", funcs.AllOf(
funcs.ResourcesHaveConditionWithin(1*time.Minute, setupPath, "definition.yaml", apiextensionsv1.WatchingComposite()),
funcs.ResourcesHaveConditionWithin(2*time.Minute, setupPath, "provider.yaml", pkgv1.Healthy(), pkgv1.Active()),
)).
Assess("CanDiffNewResource", func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context {
t.Helper()
Expand Down Expand Up @@ -248,7 +244,6 @@ func TestDiffExistingResourceV2Namespaced(t *testing.T) {
)).
WithSetup("PrerequisitesAreReady", funcs.AllOf(
funcs.ResourcesHaveConditionWithin(1*time.Minute, setupPath, "definition.yaml", apiextensionsv1.WatchingComposite()),
funcs.ResourcesHaveConditionWithin(2*time.Minute, setupPath, "provider.yaml", pkgv1.Healthy(), pkgv1.Active()),
)).
WithSetup("CreateExistingXR", funcs.AllOf(
funcs.ApplyResources(e2e.FieldManager, manifests, "existing-xr.yaml"),
Expand Down Expand Up @@ -302,7 +297,6 @@ func TestDiffNewResourceV1(t *testing.T) {
)).
WithSetup("PrerequisitesAreReady", funcs.AllOf(
funcs.ResourcesHaveConditionWithin(1*time.Minute, setupPath, "definition.yaml", apiextensionsv1.WatchingComposite()),
funcs.ResourcesHaveConditionWithin(2*time.Minute, setupPath, "provider.yaml", pkgv1.Healthy(), pkgv1.Active()),
)).
Assess("CanDiffNewResource", func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context {
t.Helper()
Expand Down Expand Up @@ -348,7 +342,6 @@ func TestDiffExistingResourceV1(t *testing.T) {
)).
WithSetup("PrerequisitesAreReady", funcs.AllOf(
funcs.ResourcesHaveConditionWithin(1*time.Minute, setupPath, "definition.yaml", apiextensionsv1.WatchingComposite()),
funcs.ResourcesHaveConditionWithin(2*time.Minute, setupPath, "provider.yaml", pkgv1.Healthy(), pkgv1.Active()),
)).
WithSetup("CreateXR", funcs.AllOf(
funcs.ApplyResources(e2e.FieldManager, manifests, "existing-xr.yaml"),
Expand Down Expand Up @@ -415,7 +408,6 @@ func TestDiffNewClaim(t *testing.T) {
)).
WithSetup("PrerequisitesAreReady", funcs.AllOf(
funcs.ResourcesHaveConditionWithin(1*time.Minute, setupPath, "definition.yaml", apiextensionsv1.WatchingComposite()),
funcs.ResourcesHaveConditionWithin(2*time.Minute, setupPath, "provider.yaml", pkgv1.Healthy(), pkgv1.Active()),
)).
Assess("CanDiffNewClaim", func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context {
t.Helper()
Expand Down Expand Up @@ -461,7 +453,6 @@ func TestDiffExistingClaim(t *testing.T) {
)).
WithSetup("PrerequisitesAreReady", funcs.AllOf(
funcs.ResourcesHaveConditionWithin(1*time.Minute, setupPath, "definition.yaml", apiextensionsv1.WatchingComposite()),
funcs.ResourcesHaveConditionWithin(2*time.Minute, setupPath, "provider.yaml", pkgv1.Healthy(), pkgv1.Active()),
)).
WithSetup("CreateClaim", funcs.AllOf(
funcs.ApplyResources(e2e.FieldManager, manifests, "existing-claim.yaml"),
Expand Down Expand Up @@ -705,7 +696,6 @@ func TestDiffExistingComposition(t *testing.T) {
)).
WithSetup("PrerequisitesAreReady", funcs.AllOf(
funcs.ResourcesHaveConditionWithin(1*time.Minute, setupPath, "definition.yaml", apiextensionsv1.WatchingComposite()),
funcs.ResourcesHaveConditionWithin(2*time.Minute, setupPath, "provider.yaml", pkgv1.Healthy(), pkgv1.Active()),
)).
WithSetup("CreateExistingXR", funcs.AllOf(
funcs.ApplyResources(e2e.FieldManager, manifests, "existing-xr.yaml"),
Expand Down Expand Up @@ -753,8 +743,6 @@ func TestDiffConcurrentDirectory(t *testing.T) {
)).
WithSetup("PrerequisitesAreReady", funcs.AllOf(
funcs.ResourcesHaveConditionWithin(1*time.Minute, setupPath, "definition.yaml", apiextensionsv1.WatchingComposite()),
funcs.ResourcesHaveConditionWithin(2*time.Minute, setupPath, "provider.yaml", pkgv1.Healthy(), pkgv1.Active()),
funcs.ResourcesHaveConditionWithin(3*time.Minute, setupPath, "functions.yaml", pkgv1.Healthy(), pkgv1.Active()),
)).
Assess("CanProcessDirectoryWithMultipleXRs", func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context {
t.Helper()
Expand Down Expand Up @@ -819,7 +807,6 @@ func TestDiffNewNestedResourceV2(t *testing.T) {
WithSetup("PrerequisitesAreReady", funcs.AllOf(
funcs.ResourcesHaveConditionWithin(1*time.Minute, setupPath, "parent-definition.yaml", apiextensionsv1.WatchingComposite()),
funcs.ResourcesHaveConditionWithin(1*time.Minute, setupPath, "child-definition.yaml", apiextensionsv1.WatchingComposite()),
funcs.ResourcesHaveConditionWithin(2*time.Minute, setupPath, "provider.yaml", pkgv1.Healthy(), pkgv1.Active()),
)).
Assess("CanDiffNewNestedResource", func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context {
t.Helper()
Expand All @@ -835,10 +822,6 @@ func TestDiffNewNestedResourceV2(t *testing.T) {
}).
WithTeardown("DeletePrerequisites", funcs.AllOf(
funcs.ResourcesDeletedAfterListedAreGone(3*time.Minute, setupPath, "*.yaml", nsNopList),
funcs.ResourceDeletedWithin(3*time.Minute, &k8sapiextensionsv1.CustomResourceDefinition{
TypeMeta: metav1.TypeMeta{Kind: "CustomResourceDefinition", APIVersion: "apiextensions.k8s.io/v1"},
ObjectMeta: metav1.ObjectMeta{Name: "nopresources.nop.crossplane.io"},
}),
)).
Feature(),
)
Expand All @@ -864,7 +847,6 @@ func TestDiffExistingNestedResourceV2(t *testing.T) {
WithSetup("PrerequisitesAreReady", funcs.AllOf(
funcs.ResourcesHaveConditionWithin(1*time.Minute, setupPath, "parent-definition.yaml", apiextensionsv1.WatchingComposite()),
funcs.ResourcesHaveConditionWithin(1*time.Minute, setupPath, "child-definition.yaml", apiextensionsv1.WatchingComposite()),
funcs.ResourcesHaveConditionWithin(2*time.Minute, setupPath, "provider.yaml", pkgv1.Healthy(), pkgv1.Active()),
)).
WithSetup("CreateExistingXR", funcs.AllOf(
funcs.ApplyResources(e2e.FieldManager, manifests, "existing-parent-xr.yaml"),
Expand All @@ -891,10 +873,6 @@ func TestDiffExistingNestedResourceV2(t *testing.T) {
)).
WithTeardown("DeletePrerequisites", funcs.AllOf(
funcs.ResourcesDeletedAfterListedAreGone(3*time.Minute, setupPath, "*.yaml", nsNopList),
funcs.ResourceDeletedWithin(3*time.Minute, &k8sapiextensionsv1.CustomResourceDefinition{
TypeMeta: metav1.TypeMeta{Kind: "CustomResourceDefinition", APIVersion: "apiextensions.k8s.io/v1"},
ObjectMeta: metav1.ObjectMeta{Name: "nopresources.nop.crossplane.io"},
}),
)).
Feature(),
)
Expand Down
99 changes: 99 additions & 0 deletions test/e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,31 @@ package e2e

import (
"context"
"errors"
"fmt"
"io"
"os"
"path/filepath"
"strings"
"testing"
"time"

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/e2e-framework/klient/conf"
"sigs.k8s.io/e2e-framework/klient/k8s"
"sigs.k8s.io/e2e-framework/klient/wait"
"sigs.k8s.io/e2e-framework/klient/wait/conditions"
"sigs.k8s.io/e2e-framework/pkg/env"
"sigs.k8s.io/e2e-framework/pkg/envconf"
"sigs.k8s.io/e2e-framework/pkg/envfuncs"
"sigs.k8s.io/e2e-framework/pkg/features"
"sigs.k8s.io/e2e-framework/support/kind"
"sigs.k8s.io/e2e-framework/third_party/helm"

pkgv1 "github.com/crossplane/crossplane/v2/apis/pkg/v1"
"github.com/crossplane/crossplane/v2/test/e2e/config"
"github.com/crossplane/crossplane/v2/test/e2e/funcs"
)
Expand Down Expand Up @@ -133,6 +143,95 @@ func TestMain(m *testing.M) {
// We always want to add our types to the scheme.
setup = append(setup, funcs.AddCrossplaneTypesToScheme(), funcs.AddCRDsToScheme())

// Install shared functions and providers for all tests in this variant
sharedSetupPath := filepath.Join("test/e2e/manifests/beta/diff", imageTag, "_setup")

setup = append(setup, func(ctx context.Context, cfg *envconf.Config) (context.Context, error) {
client, err := cfg.NewClient()
if err != nil {
return ctx, fmt.Errorf("failed to create k8s client: %w", err)
}

// Read and apply all YAML files in the setup directory
files, err := filepath.Glob(filepath.Join(sharedSetupPath, "*.yaml"))
if err != nil {
return ctx, fmt.Errorf("failed to glob setup files: %w", err)
}

for _, file := range files {
f, err := os.Open(file)
if err != nil {
return ctx, fmt.Errorf("failed to open %s: %w", file, err)
}

decoder := yaml.NewYAMLOrJSONDecoder(f, 4096)

for {
obj := &unstructured.Unstructured{}
if err := decoder.Decode(obj); err != nil {
if errors.Is(err, io.EOF) {
break
}

f.Close()

return ctx, fmt.Errorf("failed to decode %s: %w", file, err)
}

if err := client.Resources().Create(ctx, obj); err != nil {
f.Close()
return ctx, fmt.Errorf("failed to create resource from %s: %w", file, err)
}
}

f.Close()
}

// Wait for functions to be ready
functionList := &pkgv1.FunctionList{}
if err := wait.For(conditions.New(client.Resources()).ResourcesFound(functionList), wait.WithTimeout(30*time.Second)); err != nil {
return ctx, fmt.Errorf("functions not found: %w", err)
}

if err := client.Resources().List(ctx, functionList); err != nil {
return ctx, fmt.Errorf("failed to list functions: %w", err)
}

for _, fn := range functionList.Items {
obj := fn.DeepCopy()
if err := wait.For(conditions.New(client.Resources()).ResourceMatch(obj, func(object k8s.Object) bool {
fn := object.(*pkgv1.Function)
return fn.Status.GetCondition(pkgv1.TypeHealthy).Status == "True" &&
fn.Status.GetCondition(pkgv1.TypeInstalled).Status == "True"
}), wait.WithTimeout(3*time.Minute)); err != nil {
return ctx, fmt.Errorf("function %s not ready: %w", fn.Name, err)
}
}

// Wait for provider to be ready
providerList := &pkgv1.ProviderList{}
if err := wait.For(conditions.New(client.Resources()).ResourcesFound(providerList), wait.WithTimeout(30*time.Second)); err != nil {
return ctx, fmt.Errorf("providers not found: %w", err)
}

if err := client.Resources().List(ctx, providerList); err != nil {
return ctx, fmt.Errorf("failed to list providers: %w", err)
}

for _, prov := range providerList.Items {
obj := prov.DeepCopy()
if err := wait.For(conditions.New(client.Resources()).ResourceMatch(obj, func(object k8s.Object) bool {
prov := object.(*pkgv1.Provider)
return prov.Status.GetCondition(pkgv1.TypeHealthy).Status == "True" &&
prov.Status.GetCondition(pkgv1.TypeInstalled).Status == "True"
}), wait.WithTimeout(2*time.Minute)); err != nil {
return ctx, fmt.Errorf("provider %s not ready: %w", prov.Name, err)
}
}

return ctx, nil
})

if environment.ShouldCollectKindLogsOnFailure() {
finish = append(finish, envfuncs.ExportClusterLogs(environment.GetKindClusterName(), environment.GetKindClusterLogsLocation()))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ spec:
---
apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
name: function-go-templating
spec:
package: xpkg.upbound.io/crossplane-contrib/function-go-templating:v0.11.0
---
apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
name: function-auto-ready
spec:
Expand Down
22 changes: 0 additions & 22 deletions test/e2e/manifests/beta/diff/main/comp/setup/provider.yaml

This file was deleted.

13 changes: 0 additions & 13 deletions test/e2e/manifests/beta/diff/main/v1-claim/setup/functions.yaml

This file was deleted.

13 changes: 0 additions & 13 deletions test/e2e/manifests/beta/diff/main/v1/setup/functions.yaml

This file was deleted.

7 changes: 0 additions & 7 deletions test/e2e/manifests/beta/diff/main/v1/setup/provider.yaml

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading