@@ -40,8 +40,8 @@ import (
4040
4141// WebhookInstallOptions are the options for installing mutating or validating webhooks
4242type 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
4545
4646 // MutatingWebhooks is a list of MutatingWebhookConfigurations to install
4747 MutatingWebhooks []runtime.Object
@@ -149,7 +149,7 @@ func (o *WebhookInstallOptions) Install(config *rest.Config) error {
149149 if err != nil {
150150 return err
151151 }
152- if err := parseWebhookDirs (o ); err != nil {
152+ if err := parseWebhook (o ); err != nil {
153153 return err
154154 }
155155
@@ -319,10 +319,10 @@ func ensureCreated(cs client.Client, obj *unstructured.Unstructured) error {
319319 return nil
320320}
321321
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 {
326326 _ , err := os .Stat (path )
327327 if options .IgnoreErrorIfPathMissing && os .IsNotExist (err ) {
328328 continue // skip this path
@@ -348,9 +348,17 @@ func readWebhooks(path string) ([]runtime.Object, []runtime.Object, error) {
348348 var files []os.FileInfo
349349 var err error
350350 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 {
352353 return nil , nil , err
353354 }
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+ }
354362
355363 // file extensions that may contain Webhooks
356364 resourceExtensions := sets .NewString (".json" , ".yaml" , ".yml" )
0 commit comments