Skip to content

Commit 5547262

Browse files
committed
add basic e2e test for crd bootstrap
this also bumps to kube 1.28 dependencies to deal with: kubernetes/kubernetes#118340
1 parent d52afdf commit 5547262

File tree

12 files changed

+328
-205
lines changed

12 files changed

+328
-205
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.kubeconfig

bootstrap/crds.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"time"
99

1010
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
11-
v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1211
"k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
1312
k8serrors "k8s.io/apimachinery/pkg/api/errors"
1413
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -27,15 +26,21 @@ const (
2726
)
2827

2928
// CRD installs the CRDs in the filesystem into the kube cluster configured by the rest config.
30-
func CRD(ctx context.Context, restConfig *rest.Config, crdFS fs.ReadDirFS, dir string) error {
31-
crds := make([]*v1.CustomResourceDefinition, 0)
29+
// Deprecated: Use CRDs instead.
30+
func CRD(restConfig *rest.Config, crdFS fs.ReadDirFS, dir string) error {
31+
return CRDs(context.Background(), restConfig, crdFS, dir)
32+
}
33+
34+
// CRDs installs the CRDs in the filesystem into the kube cluster configured by the rest config.
35+
func CRDs(ctx context.Context, restConfig *rest.Config, crdFS fs.ReadDirFS, dir string) error {
36+
crds := make([]*apiextensionsv1.CustomResourceDefinition, 0)
3237

3338
crdFiles, err := crdFS.ReadDir(dir)
3439
if err != nil {
3540
return err
3641
}
3742
for _, crdFile := range crdFiles {
38-
var crd v1.CustomResourceDefinition
43+
var crd apiextensionsv1.CustomResourceDefinition
3944
file, err := crdFS.Open(path.Join(dir, crdFile.Name()))
4045
if err != nil {
4146
return err

bootstrap/crds_e2e_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//go:build e2e
2+
3+
package bootstrap
4+
5+
import (
6+
"context"
7+
"testing"
8+
9+
"github.com/stretchr/testify/require"
10+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11+
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
12+
"k8s.io/apimachinery/pkg/runtime/schema"
13+
"k8s.io/cli-runtime/pkg/genericclioptions"
14+
cmdutil "k8s.io/kubectl/pkg/cmd/util"
15+
"k8s.io/utils/pointer"
16+
)
17+
18+
func TestCRD(t *testing.T) {
19+
opts := genericclioptions.NewConfigFlags(true)
20+
opts.KubeConfig = pointer.String("../controller-idioms-e2e.kubeconfig")
21+
factory := cmdutil.NewFactory(opts)
22+
restConfig, err := factory.ToRESTConfig()
23+
require.NoError(t, err)
24+
25+
// ensure CRDs
26+
require.NoError(t, CRDs(context.Background(), restConfig, crdFS, "example"))
27+
28+
// create an object
29+
client, err := factory.DynamicClient()
30+
require.NoError(t, err)
31+
_, err = client.Resource(schema.GroupVersionResource{
32+
Group: "example.com",
33+
Version: "v1",
34+
Resource: "mytypes",
35+
}).Namespace("default").Create(context.Background(), &unstructured.Unstructured{Object: map[string]any{
36+
"kind": "MyType",
37+
"apiVersion": "example.com/v1",
38+
"metadata": map[string]any{"generateName": "test"},
39+
}}, metav1.CreateOptions{})
40+
require.NoError(t, err)
41+
}

bootstrap/crds_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ import (
1111
var crdFS embed.FS
1212

1313
func ExampleCRD() {
14-
_ = CRD(context.Background(), &rest.Config{}, crdFS, "example")
14+
_ = CRDs(context.Background(), &rest.Config{}, crdFS, "example")
1515
// Output:
1616
}

bootstrap/example/crd.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
apiVersion: "apiextensions.k8s.io/v1"
33
kind: "CustomResourceDefinition"
44
metadata:
5-
name: "mytype.example.com"
5+
name: "mytypes.example.com"
66
spec:
77
group: "example.com"
88
names:
@@ -15,3 +15,6 @@ spec:
1515
- name: "v1"
1616
served: true
1717
storage: true
18+
schema:
19+
openAPIV3Schema:
20+
type: "object"

go.mod

Lines changed: 54 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,41 @@ require (
88
github.com/fsnotify/fsnotify v1.6.0
99
github.com/go-logr/logr v1.2.4
1010
github.com/maxbrunsfeld/counterfeiter/v6 v6.7.0
11-
github.com/prometheus/client_golang v1.14.0
11+
github.com/prometheus/client_golang v1.16.0
1212
github.com/stretchr/testify v1.8.4
1313
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1
1414
golang.org/x/sync v0.3.0
15-
k8s.io/api v0.27.2
16-
k8s.io/apiextensions-apiserver v0.27.2
17-
k8s.io/apimachinery v0.27.2
18-
k8s.io/apiserver v0.27.2
19-
k8s.io/client-go v0.27.2
20-
k8s.io/component-base v0.27.2
21-
k8s.io/controller-manager v0.27.2
22-
k8s.io/klog/v2 v2.90.1
23-
k8s.io/utils v0.0.0-20230209194617-a36077c30491
15+
k8s.io/api v0.28.0
16+
k8s.io/apiextensions-apiserver v0.28.0
17+
k8s.io/apimachinery v0.28.0
18+
k8s.io/apiserver v0.28.0
19+
k8s.io/cli-runtime v0.28.0
20+
k8s.io/client-go v0.28.0
21+
k8s.io/component-base v0.28.0
22+
k8s.io/controller-manager v0.28.0
23+
k8s.io/klog/v2 v2.100.1
24+
k8s.io/kubectl v0.28.0
25+
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2
2426
)
2527

2628
require (
2729
github.com/NYTimes/gziphandler v1.1.1 // indirect
28-
github.com/antlr/antlr4/runtime/Go/antlr v1.4.10 // indirect
2930
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect
3031
github.com/beorn7/perks v1.0.1 // indirect
3132
github.com/blang/semver/v4 v4.0.0 // indirect
32-
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
33-
github.com/coreos/go-semver v0.3.0 // indirect
34-
github.com/coreos/go-systemd/v22 v22.4.0 // indirect
33+
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
34+
github.com/coreos/go-semver v0.3.1 // indirect
35+
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
3536
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
36-
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
37+
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
3738
github.com/felixge/httpsnoop v1.0.3 // indirect
3839
github.com/go-logr/stdr v1.2.2 // indirect
39-
github.com/go-openapi/jsonpointer v0.19.6 // indirect
40-
github.com/go-openapi/jsonreference v0.20.1 // indirect
41-
github.com/go-openapi/swag v0.22.3 // indirect
4240
github.com/gogo/protobuf v1.3.2 // indirect
4341
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
4442
github.com/golang/protobuf v1.5.3 // indirect
45-
github.com/google/cel-go v0.12.6 // indirect
46-
github.com/google/gnostic v0.5.7-v3refs // indirect
43+
github.com/google/cel-go v0.16.0 // indirect
4744
github.com/google/go-cmp v0.5.9 // indirect
48-
github.com/google/gofuzz v1.1.0 // indirect
45+
github.com/google/gofuzz v1.2.0 // indirect
4946
github.com/google/pprof v0.0.0-20230705174524-200ffdc848b8 // indirect
5047
github.com/google/uuid v1.3.0 // indirect
5148
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
@@ -55,43 +52,41 @@ require (
5552
github.com/josharian/intern v1.0.0 // indirect
5653
github.com/json-iterator/go v1.1.12 // indirect
5754
github.com/mailru/easyjson v0.7.7 // indirect
58-
github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect
59-
github.com/mitchellh/mapstructure v1.4.1 // indirect
55+
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
6056
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
6157
github.com/modern-go/reflect2 v1.0.2 // indirect
6258
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
6359
github.com/pkg/errors v0.9.1 // indirect
6460
github.com/pmezard/go-difflib v1.0.0 // indirect
65-
github.com/prometheus/client_model v0.3.0 // indirect
66-
github.com/prometheus/common v0.37.0 // indirect
67-
github.com/prometheus/procfs v0.8.0 // indirect
61+
github.com/prometheus/client_model v0.4.0 // indirect
62+
github.com/prometheus/common v0.44.0 // indirect
63+
github.com/prometheus/procfs v0.10.1 // indirect
6864
github.com/sirupsen/logrus v1.9.3 // indirect
6965
github.com/spf13/cobra v1.7.0 // indirect
7066
github.com/spf13/pflag v1.0.5 // indirect
7167
github.com/stoewer/go-strcase v1.2.0 // indirect
7268
github.com/stretchr/objx v0.5.0 // indirect
73-
go.etcd.io/etcd/api/v3 v3.5.7 // indirect
74-
go.etcd.io/etcd/client/pkg/v3 v3.5.7 // indirect
75-
go.etcd.io/etcd/client/v3 v3.5.7 // indirect
69+
go.etcd.io/etcd/api/v3 v3.5.9 // indirect
70+
go.etcd.io/etcd/client/pkg/v3 v3.5.9 // indirect
71+
go.etcd.io/etcd/client/v3 v3.5.9 // indirect
7672
go.uber.org/atomic v1.11.0 // indirect
7773
go.uber.org/multierr v1.11.0 // indirect
7874
go.uber.org/zap v1.24.0 // indirect
7975
golang.org/x/crypto v0.12.0 // indirect
8076
golang.org/x/net v0.14.0 // indirect
81-
golang.org/x/oauth2 v0.7.0 // indirect
77+
golang.org/x/oauth2 v0.8.0 // indirect
8278
golang.org/x/sys v0.11.0 // indirect
8379
golang.org/x/term v0.11.0 // indirect
8480
golang.org/x/text v0.12.0 // indirect
8581
golang.org/x/time v0.3.0 // indirect
8682
golang.org/x/tools v0.12.0 // indirect
8783
google.golang.org/appengine v1.6.7 // indirect
88-
google.golang.org/genproto v0.0.0-20230323212658-478b75c54725 // indirect
84+
google.golang.org/genproto v0.0.0-20230526161137-0005af68ea54 // indirect
8985
google.golang.org/grpc v1.54.0 // indirect
9086
google.golang.org/protobuf v1.31.0 // indirect
9187
gopkg.in/inf.v0 v0.9.1 // indirect
9288
gopkg.in/yaml.v2 v2.4.0 // indirect
9389
gopkg.in/yaml.v3 v3.0.1 // indirect
94-
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect
9590
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.1.2 // indirect
9691
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
9792
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
@@ -100,6 +95,27 @@ require (
10095

10196
require (
10297
cloud.google.com/go/compute v1.19.1 // indirect
98+
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
99+
github.com/MakeNowJust/heredoc v1.0.0 // indirect
100+
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df // indirect
101+
github.com/chai2010/gettext-go v1.0.2 // indirect
102+
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
103+
github.com/go-errors/errors v1.4.2 // indirect
104+
github.com/go-openapi/jsonpointer v0.19.6 // indirect
105+
github.com/go-openapi/jsonreference v0.20.2 // indirect
106+
github.com/go-openapi/swag v0.22.3 // indirect
107+
github.com/google/btree v1.0.1 // indirect
108+
github.com/google/gnostic-models v0.6.8 // indirect
109+
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
110+
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
111+
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
112+
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
113+
github.com/moby/spdystream v0.2.0 // indirect
114+
github.com/moby/term v0.0.0-20221205130635-1aeaba878587 // indirect
115+
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
116+
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
117+
github.com/russross/blackfriday/v2 v2.1.0 // indirect
118+
github.com/xlab/treeprint v1.2.0 // indirect
103119
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.35.0 // indirect
104120
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.35.1 // indirect
105121
go.opentelemetry.io/otel v1.10.0 // indirect
@@ -110,5 +126,11 @@ require (
110126
go.opentelemetry.io/otel/sdk v1.10.0 // indirect
111127
go.opentelemetry.io/otel/trace v1.10.0 // indirect
112128
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
129+
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect
113130
golang.org/x/mod v0.12.0 // indirect
131+
google.golang.org/genproto/googleapis/api v0.0.0-20230525234035-dd9d682886f9 // indirect
132+
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect
133+
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
134+
sigs.k8s.io/kustomize/api v0.13.5-0.20230601165947-6ce0bf390ce3 // indirect
135+
sigs.k8s.io/kustomize/kyaml v0.14.3-0.20230601165947-6ce0bf390ce3 // indirect
114136
)

0 commit comments

Comments
 (0)