Skip to content

Commit cb6494a

Browse files
committed
pkg/envtest: validate config when handling CRDs
Thie error message is adapted from pkg/client. Otherwise, if nil is passed, it crashes with a longer stack trace. Signed-off-by: Daniel Maslowski <info@orangecms.org>
1 parent d3eaef3 commit cb6494a

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

pkg/envtest/crd.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ const (
9090

9191
// InstallCRDs installs a collection of CRDs into a cluster by reading the crd yaml files from a directory.
9292
func InstallCRDs(config *rest.Config, options CRDInstallOptions) ([]*apiextensionsv1.CustomResourceDefinition, error) {
93+
if config == nil {
94+
return fmt.Errorf("must provide non-nil rest.Config to InstallCRDs")
95+
}
96+
9397
defaultCRDOptions(&options)
9498

9599
// Read the CRD yamls into options.CRDs
@@ -142,6 +146,10 @@ func defaultCRDOptions(o *CRDInstallOptions) {
142146

143147
// WaitForCRDs waits for the CRDs to appear in discovery.
144148
func WaitForCRDs(config *rest.Config, crds []*apiextensionsv1.CustomResourceDefinition, options CRDInstallOptions) error {
149+
if config == nil {
150+
return fmt.Errorf("must provide non-nil rest.Config to WaitForCRDs")
151+
}
152+
145153
// Add each CRD to a map of GroupVersion to Resource
146154
waitingFor := map[schema.GroupVersion]*sets.Set[string]{}
147155
for _, crd := range crds {
@@ -215,6 +223,10 @@ func (p *poller) poll(ctx context.Context) (done bool, err error) {
215223

216224
// UninstallCRDs uninstalls a collection of CRDs by reading the crd yaml files from a directory.
217225
func UninstallCRDs(config *rest.Config, options CRDInstallOptions) error {
226+
if config == nil {
227+
return fmt.Errorf("must provide non-nil rest.Config to UninstallCRDs")
228+
}
229+
218230
// Read the CRD yamls into options.CRDs
219231
if err := ReadCRDFiles(&options); err != nil {
220232
return err
@@ -242,6 +254,10 @@ func UninstallCRDs(config *rest.Config, options CRDInstallOptions) error {
242254

243255
// CreateCRDs creates the CRDs.
244256
func CreateCRDs(config *rest.Config, crds []*apiextensionsv1.CustomResourceDefinition) error {
257+
if config == nil {
258+
return fmt.Errorf("must provide non-nil rest.Config to CreateCRDs")
259+
}
260+
245261
cs, err := client.New(config, client.Options{})
246262
if err != nil {
247263
return fmt.Errorf("unable to create client: %w", err)

0 commit comments

Comments
 (0)