Skip to content

Commit

Permalink
feat: remove dependency to crossplane/crossplane (#22)
Browse files Browse the repository at this point in the history
fixes #20 

One caveat: we had to vendor the type for controller config. in a follow
up, we should already enable the new type for that, the same way, but
maybe better then with automatically copying… Or we just let the user
create a the controller config (or future thing) and patch the
unstructured.

Additionally we got rid of the controller-runtime dependency.
  • Loading branch information
maximilianbraun committed Nov 24, 2023
2 parents b75f0d6 + b245e58 commit 2e4ef4e
Show file tree
Hide file tree
Showing 11 changed files with 622 additions and 215 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ run:

skip-files:
- "zz_generated\\..+\\.go$"
- "vendored/.+\\.go$"

build-tags:
- e2e
Expand Down
8 changes: 4 additions & 4 deletions e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (
"os"
"testing"

"github.com/crossplane-contrib/xp-testing/pkg/vendored"
"github.com/vladimirvivien/gexe"
"k8s.io/klog/v2"
"sigs.k8s.io/e2e-framework/pkg/envconf"
"sigs.k8s.io/e2e-framework/support/kind"

xpv1alpha1 "github.com/crossplane/crossplane/apis/pkg/v1alpha1"
"sigs.k8s.io/e2e-framework/pkg/env"

"github.com/crossplane-contrib/xp-testing/pkg/images"
Expand Down Expand Up @@ -41,8 +41,8 @@ func TestMain(m *testing.M) {
ProviderName: "provider-nop",
Images: imgs,
CrossplaneVersion: "1.14.0",
ControllerConfig: &xpv1alpha1.ControllerConfig{
Spec: xpv1alpha1.ControllerConfigSpec{
ControllerConfig: &vendored.ControllerConfig{
Spec: vendored.ControllerConfigSpec{
Image: &imgs.Package,
},
},
Expand All @@ -58,7 +58,7 @@ func TestMain(m *testing.M) {
}

func pullPackageOrPanic(image string) {
klog.Info("Pulling %s", image)
klog.Info("Pulling ", image)
runner := gexe.New()
p := runner.RunProc(fmt.Sprintf("docker pull %s", image))
klog.V(4).Info(p.Out())
Expand Down
1 change: 0 additions & 1 deletion e2e/provider/config.yaml
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
---
17 changes: 4 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ go 1.20

require (
github.com/GoogleContainerTools/container-diff v0.17.0
github.com/crossplane/crossplane v1.14.1
github.com/crossplane/crossplane-runtime v1.14.2
github.com/google/go-cmp v0.6.0
github.com/crossplane/crossplane-runtime v0.19.3
github.com/pkg/errors v0.9.1
github.com/samber/lo v1.38.1
github.com/stretchr/testify v1.8.4
Expand All @@ -16,16 +14,12 @@ require (
k8s.io/apimachinery v0.28.4
k8s.io/client-go v0.28.4
k8s.io/klog/v2 v2.100.1
sigs.k8s.io/controller-runtime v0.16.3
sigs.k8s.io/e2e-framework v0.3.0
sigs.k8s.io/kind v0.20.0
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/BurntSushi/toml v1.2.1 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/alessio/shellescape v1.4.1 // indirect
github.com/containerd/continuity v0.0.0-20181203112020-004b46473808 // indirect
github.com/containerd/stargz-snapshotter/estargz v0.14.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand All @@ -45,17 +39,15 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/go-containerregistry v0.16.1 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/safetext v0.0.0-20220905092116-b49f7bc46da2 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.1 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
Expand All @@ -64,11 +56,9 @@ require (
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc5 // indirect
github.com/opencontainers/runc v0.1.1 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/vbatts/tar-split v0.11.5 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
Expand All @@ -88,6 +78,7 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
sigs.k8s.io/controller-runtime v0.16.3 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
Expand Down
60 changes: 10 additions & 50 deletions go.sum

Large diffs are not rendered by default.

25 changes: 13 additions & 12 deletions pkg/resources/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@ import (
"time"

"github.com/crossplane-contrib/xp-testing/pkg/xpconditions"

crossplanev1 "github.com/crossplane/crossplane/apis/pkg/v1"
"github.com/samber/lo"
v1extensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/dynamic"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/e2e-framework/klient/decoder"
"sigs.k8s.io/e2e-framework/klient/k8s"
"sigs.k8s.io/e2e-framework/klient/k8s/resources"
Expand All @@ -29,6 +27,10 @@ import (
"sigs.k8s.io/e2e-framework/pkg/envconf"
)

var (
providerSchema = schema.GroupVersionResource{Group: "pkg.crossplane.io", Version: "v1", Resource: "providers"}
)

// ImportResources gets the resources from dir
func ImportResources(ctx context.Context, t *testing.T, cfg *envconf.Config, dir string) {
r := resClient(cfg)
Expand Down Expand Up @@ -95,8 +97,8 @@ func WaitForResourcesToBeSynced(
}

type mockList struct {
client.ObjectList

metav1.ListInterface
runtime.Object
Items []k8s.Object
}

Expand Down Expand Up @@ -138,16 +140,15 @@ func DumpManagedResources(ctx context.Context, t *testing.T, cfg *envconf.Config
}

func dumpProviders(ctx context.Context, t *testing.T, client *resources.Resources) {
var providers crossplanev1.ProviderList
dynamiq := dynamic.NewForConfigOrDie(client.GetConfig())

if err := crossplanev1.AddToScheme(client.GetScheme()); err != nil {
t.Fatal(err)
}

if err := client.List(ctx, &providers); err != nil {
res := dynamiq.Resource(providerSchema)
list, err := res.List(ctx, metav1.ListOptions{})
if err != nil {
t.Fatal(err)
return
}
for _, provider := range providers.Items {
for _, provider := range list.Items {
t.Log(provider)
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"

"github.com/crossplane-contrib/xp-testing/pkg/envvar"
"github.com/crossplane/crossplane/apis/pkg/v1alpha1"
"github.com/crossplane-contrib/xp-testing/pkg/vendored"
"github.com/vladimirvivien/gexe"
"k8s.io/apimachinery/pkg/runtime"
log "k8s.io/klog/v2"
Expand All @@ -29,7 +29,7 @@ const (
type ClusterSetup struct {
ProviderName string
Images images.ProviderImages
ControllerConfig *v1alpha1.ControllerConfig
ControllerConfig *vendored.ControllerConfig
SecretData map[string]string
AddToSchemaFuncs []func(s *runtime.Scheme) error
CrossplaneVersion string
Expand Down
Loading

0 comments on commit 2e4ef4e

Please sign in to comment.