@@ -16,7 +16,6 @@ package envtest
16
16
import (
17
17
"context"
18
18
"fmt"
19
- "io/ioutil"
20
19
"net"
21
20
"os"
22
21
"path/filepath"
@@ -266,7 +265,7 @@ func (o *WebhookInstallOptions) setupCA() error {
266
265
return fmt .Errorf ("unable to set up webhook serving certs: %w" , err )
267
266
}
268
267
269
- localServingCertsDir , err := ioutil . TempDir ("" , "envtest-serving-certs-" )
268
+ localServingCertsDir , err := os . MkdirTemp ("" , "envtest-serving-certs-" )
270
269
o .LocalServingCertDir = localServingCertsDir
271
270
if err != nil {
272
271
return fmt .Errorf ("unable to create directory for webhook serving certs: %w" , err )
@@ -277,10 +276,10 @@ func (o *WebhookInstallOptions) setupCA() error {
277
276
return fmt .Errorf ("unable to marshal webhook serving certs: %w" , err )
278
277
}
279
278
280
- if err := ioutil .WriteFile (filepath .Join (localServingCertsDir , "tls.crt" ), certData , 0640 ); err != nil { //nolint:gosec
279
+ if err := os .WriteFile (filepath .Join (localServingCertsDir , "tls.crt" ), certData , 0640 ); err != nil { //nolint:gosec
281
280
return fmt .Errorf ("unable to write webhook serving cert to disk: %w" , err )
282
281
}
283
- if err := ioutil .WriteFile (filepath .Join (localServingCertsDir , "tls.key" ), keyData , 0640 ); err != nil { //nolint:gosec
282
+ if err := os .WriteFile (filepath .Join (localServingCertsDir , "tls.key" ), keyData , 0640 ); err != nil { //nolint:gosec
284
283
return fmt .Errorf ("unable to write webhook serving key to disk: %w" , err )
285
284
}
286
285
@@ -359,17 +358,23 @@ func parseWebhook(options *WebhookInstallOptions) error {
359
358
// returns slice of mutating and validating webhook configurations.
360
359
func readWebhooks (path string ) ([]* admissionv1.MutatingWebhookConfiguration , []* admissionv1.ValidatingWebhookConfiguration , error ) {
361
360
// Get the webhook files
362
- var files []os. FileInfo
361
+ var files []string
363
362
var err error
364
363
log .V (1 ).Info ("reading Webhooks from path" , "path" , path )
365
364
info , err := os .Stat (path )
366
365
if err != nil {
367
366
return nil , nil , err
368
367
}
369
368
if ! info .IsDir () {
370
- path , files = filepath .Dir (path ), []os.FileInfo {info }
371
- } else if files , err = ioutil .ReadDir (path ); err != nil {
372
- return nil , nil , err
369
+ path , files = filepath .Dir (path ), []string {info .Name ()}
370
+ } else {
371
+ entries , err := os .ReadDir (path )
372
+ if err != nil {
373
+ return nil , nil , err
374
+ }
375
+ for _ , e := range entries {
376
+ files = append (files , e .Name ())
377
+ }
373
378
}
374
379
375
380
// file extensions that may contain Webhooks
@@ -379,12 +384,12 @@ func readWebhooks(path string) ([]*admissionv1.MutatingWebhookConfiguration, []*
379
384
var valHooks []* admissionv1.ValidatingWebhookConfiguration
380
385
for _ , file := range files {
381
386
// Only parse allowlisted file types
382
- if ! resourceExtensions .Has (filepath .Ext (file . Name () )) {
387
+ if ! resourceExtensions .Has (filepath .Ext (file )) {
383
388
continue
384
389
}
385
390
386
391
// Unmarshal Webhooks from file into structs
387
- docs , err := readDocuments (filepath .Join (path , file . Name () ))
392
+ docs , err := readDocuments (filepath .Join (path , file ))
388
393
if err != nil {
389
394
return nil , nil , err
390
395
}
@@ -422,7 +427,7 @@ func readWebhooks(path string) ([]*admissionv1.MutatingWebhookConfiguration, []*
422
427
}
423
428
}
424
429
425
- log .V (1 ).Info ("read webhooks from file" , "file" , file . Name () )
430
+ log .V (1 ).Info ("read webhooks from file" , "file" , file )
426
431
}
427
432
return mutHooks , valHooks , nil
428
433
}
0 commit comments