@@ -40,8 +40,8 @@ import (
40
40
41
41
// WebhookInstallOptions are the options for installing mutating or validating webhooks
42
42
type WebhookInstallOptions struct {
43
- // Paths is a list of paths to the directories containing the mutating or validating webhooks yaml or json configs.
44
- DirectoryPaths []string
43
+ // Paths is a list of paths to the directories or files containing the mutating or validating webhooks yaml or json configs.
44
+ Paths []string
45
45
46
46
// MutatingWebhooks is a list of MutatingWebhookConfigurations to install
47
47
MutatingWebhooks []runtime.Object
@@ -149,7 +149,7 @@ func (o *WebhookInstallOptions) Install(config *rest.Config) error {
149
149
if err != nil {
150
150
return err
151
151
}
152
- if err := parseWebhookDirs (o ); err != nil {
152
+ if err := parseWebhook (o ); err != nil {
153
153
return err
154
154
}
155
155
@@ -319,10 +319,10 @@ func ensureCreated(cs client.Client, obj *unstructured.Unstructured) error {
319
319
return nil
320
320
}
321
321
322
- // parseWebhookDirs reads the directories of Webhooks in options.DirectoryPaths and adds the Webhook structs to options
323
- func parseWebhookDirs (options * WebhookInstallOptions ) error {
324
- if len (options .DirectoryPaths ) > 0 {
325
- for _ , path := range options .DirectoryPaths {
322
+ // parseWebhook reads the directories or files of Webhooks in options.Paths and adds the Webhook structs to options
323
+ func parseWebhook (options * WebhookInstallOptions ) error {
324
+ if len (options .Paths ) > 0 {
325
+ for _ , path := range options .Paths {
326
326
_ , err := os .Stat (path )
327
327
if options .IgnoreErrorIfPathMissing && os .IsNotExist (err ) {
328
328
continue // skip this path
@@ -348,9 +348,17 @@ func readWebhooks(path string) ([]runtime.Object, []runtime.Object, error) {
348
348
var files []os.FileInfo
349
349
var err error
350
350
log .V (1 ).Info ("reading Webhooks from path" , "path" , path )
351
- if files , err = ioutil .ReadDir (path ); err != nil {
351
+ info , err := os .Stat (path )
352
+ if err != nil {
352
353
return nil , nil , err
353
354
}
355
+ if ! info .IsDir () {
356
+ path , files = filepath .Dir (path ), []os.FileInfo {info }
357
+ } else {
358
+ if files , err = ioutil .ReadDir (path ); err != nil {
359
+ return nil , nil , err
360
+ }
361
+ }
354
362
355
363
// file extensions that may contain Webhooks
356
364
resourceExtensions := sets .NewString (".json" , ".yaml" , ".yml" )
0 commit comments