Skip to content

Commit

Permalink
(barbican-kms-plugin)Refactor and enhance Barbican KMS plugin codebas…
Browse files Browse the repository at this point in the history
…e. (kubernetes#2278)

* Refactor and enhance Barbican KMS plugin codebase.

* fixed the formmating issue
  • Loading branch information
geet-h17 committed Jun 29, 2023
1 parent 0c5e1d2 commit 7f1e9ed
Showing 1 changed file with 13 additions and 26 deletions.
39 changes: 13 additions & 26 deletions cmd/barbican-kms-plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,49 +29,36 @@ import (
)

var (
socketpath string
cloudconfig string
socketPath string
cloudConfig string
)

func main() {
// Glog requires this otherwise it complains.
if err := flag.CommandLine.Parse(nil); err != nil {
klog.Fatalf("Unable to parse flags: %v", err)
}
flag.Parse()

// This is a temporary hack to enable proper logging until upstream dependencies
// are migrated to fully utilize klog instead of glog.
klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
klog.InitFlags(klogFlags)
// Sync the glog and klog flags.
flag.CommandLine.VisitAll(func(f1 *flag.Flag) {
f2 := klogFlags.Lookup(f1.Name)
if f2 != nil {
value := f1.Value.String()
_ = f2.Value.Set(value)
}
})
klog.InitFlags(nil)

cmd := &cobra.Command{
Use: "barbican-kms-plugin",
Short: "Barbican KMS plugin for kubernetes",
Short: "Barbican KMS plugin for Kubernetes",
RunE: func(cmd *cobra.Command, args []string) error {
sigchan := make(chan os.Signal, 1)
signal.Notify(sigchan, unix.SIGTERM, unix.SIGINT)
err := server.Run(cloudconfig, socketpath, sigchan)
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, unix.SIGTERM, unix.SIGINT)
err := server.Run(cloudConfig, socketPath, sigChan)
return err
},
}

cmd.Flags().AddGoFlagSet(flag.CommandLine)

cmd.PersistentFlags().StringVar(&socketpath, "socketpath", "", "Barbican KMS Plugin unix socket endpoint")
cmd.PersistentFlags().StringVar(&socketPath, "socketpath", "", "Barbican KMS Plugin unix socket endpoint")
if err := cmd.MarkPersistentFlagRequired("socketpath"); err != nil {
klog.Fatalf("Unable to mark flag socketpath to be required: %v", err)
klog.Fatalf("Unable to mark flag socketpath as required: %v", err)
}

cmd.PersistentFlags().StringVar(&cloudconfig, "cloud-config", "", "Barbican KMS Plugin cloud config")
cmd.PersistentFlags().StringVar(&cloudConfig, "cloud-config", "", "Barbican KMS Plugin cloud config")
if err := cmd.MarkPersistentFlagRequired("cloud-config"); err != nil {
klog.Fatalf("Unable to mark flag cloud-config to be required: %v", err)
klog.Fatalf("Unable to mark flag cloud-config as required: %v", err)
}

code := cli.Run(cmd)
Expand Down

0 comments on commit 7f1e9ed

Please sign in to comment.