This is an automated email from the ASF dual-hosted git repository.

albumenj pushed a commit to branch refactor-with-go
in repository https://gitbox.apache.org/repos/asf/dubbo-admin.git


The following commit(s) were added to refs/heads/refactor-with-go by this push:
     new 2e663f39 Refactor authority startup with cobra and viper (#1040)
2e663f39 is described below

commit 2e663f39e68561a5a4ff64531c04e92eb5e7cab9
Author: Jun <[email protected]>
AuthorDate: Mon Mar 27 07:47:52 2023 +0800

    Refactor authority startup with cobra and viper (#1040)
    
    * refactor authority startup with cobra and viper
    
    * add option ResourcelockIdentity
    
    * fix format
    
    * update go.mod
    
    * merge envflag
---
 cmd/authority/app/authority.go  | 119 ++++++++++++++++++++++++++++++++++++++++
 cmd/authority/main.go           |  25 +++------
 go.mod                          |  34 ++++++++----
 go.sum                          |  58 ++++++++++++++------
 pkg/authority/config/envflag.go | 116 ---------------------------------------
 pkg/authority/config/options.go |  98 +++++++++++++++++++++++++++++++++
 pkg/authority/k8s/client.go     |  29 +++++++---
 7 files changed, 308 insertions(+), 171 deletions(-)

diff --git a/cmd/authority/app/authority.go b/cmd/authority/app/authority.go
new file mode 100644
index 00000000..5340d8b8
--- /dev/null
+++ b/cmd/authority/app/authority.go
@@ -0,0 +1,119 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package app
+
+import (
+       "flag"
+       "fmt"
+       "log"
+       "os"
+       "os/signal"
+       "strings"
+       "syscall"
+
+       "github.com/apache/dubbo-admin/pkg/authority/config"
+       "github.com/apache/dubbo-admin/pkg/authority/security"
+       "github.com/apache/dubbo-admin/pkg/logger"
+       "github.com/spf13/cobra"
+       "github.com/spf13/pflag"
+       "github.com/spf13/viper"
+)
+
+var (
+       // For example, --webhook-port is bound to DUBBO_WEBHOOK_PORT.
+       envNamePrefix = "DUBBO"
+
+       // Replace hyphenated flag names with camelCase
+       replaceWithCamelCase = false
+)
+
+func NewAppCommand() *cobra.Command {
+       options := config.NewOptions()
+
+       cmd := &cobra.Command{
+               Use:  "authority",
+               Long: `The authority app is responsible for controllers in 
dubbo authority`,
+               PersistentPreRun: func(cmd *cobra.Command, args []string) {
+                       logger.Sugar().Infof("Authority command 
PersistentPreRun")
+                       initialize(cmd)
+               },
+               Run: func(cmd *cobra.Command, args []string) {
+                       logger.Sugar().Infof("Authority command Run with 
options: %+v", options)
+                       if errs := options.Validate(); len(errs) != 0 {
+                               log.Fatal(errs)
+                       }
+
+                       if err := Run(options); err != nil {
+                               log.Fatal(err)
+                       }
+               },
+       }
+
+       cmd.Flags().AddGoFlagSet(flag.CommandLine)
+       options.FillFlags(cmd.Flags())
+       return cmd
+}
+
+func Run(options *config.Options) error {
+       s := security.NewServer(options)
+
+       s.Init()
+       s.Start()
+
+       c := make(chan os.Signal, 1)
+       signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
+       signal.Notify(s.StopChan, syscall.SIGINT, syscall.SIGTERM)
+       signal.Notify(s.CertStorage.GetStopChan(), syscall.SIGINT, 
syscall.SIGTERM)
+
+       <-c
+
+       return nil
+}
+
+func initialize(cmd *cobra.Command) error {
+       v := viper.New()
+
+       // For example, --webhook-port is bound to DUBBO_WEBHOOK_PORT.
+       v.SetEnvPrefix(envNamePrefix)
+
+       // keys with underscores, e.g. DUBBO-WEBHOOK-PORT to DUBBO_WEBHOOK_PORT
+       v.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
+
+       // Bind to environment variables
+       v.AutomaticEnv()
+
+       // Bind the current command's flags to viper
+       bindFlags(cmd, v)
+
+       return nil
+}
+
+func bindFlags(cmd *cobra.Command, v *viper.Viper) {
+       cmd.Flags().VisitAll(func(f *pflag.Flag) {
+               configName := f.Name
+
+               //  Replace hyphens with a camelCased string.
+               if replaceWithCamelCase {
+                       configName = strings.ReplaceAll(f.Name, "-", "")
+               }
+
+               // Apply the viper config value to the flag when the flag is 
not set and viper has a value
+               if !f.Changed && v.IsSet(configName) {
+                       val := v.Get(configName)
+                       cmd.Flags().Set(f.Name, fmt.Sprintf("%v", val))
+               }
+       })
+}
diff --git a/cmd/authority/main.go b/cmd/authority/main.go
index 3129051c..fcea093b 100644
--- a/cmd/authority/main.go
+++ b/cmd/authority/main.go
@@ -16,30 +16,21 @@
 package main
 
 import (
+       "fmt"
        "os"
-       "os/signal"
-       "syscall"
 
-       "github.com/apache/dubbo-admin/pkg/authority/config"
-       "github.com/apache/dubbo-admin/pkg/authority/security"
+       "github.com/apache/dubbo-admin/cmd/authority/app"
        "github.com/apache/dubbo-admin/pkg/logger"
 )
 
 func main() {
        logger.Init()
 
-       // TODO read options from env
-       options := config.GetOptions()
+       // Convert signal to ctx
+       // ctx := signals.SetupSignalHandler()
 
-       s := security.NewServer(options)
-
-       s.Init()
-       s.Start()
-
-       c := make(chan os.Signal, 1)
-       signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
-       signal.Notify(s.StopChan, syscall.SIGINT, syscall.SIGTERM)
-       signal.Notify(s.CertStorage.GetStopChan(), syscall.SIGINT, 
syscall.SIGTERM)
-
-       <-c
+       if err := app.NewAppCommand().Execute(); err != nil {
+               fmt.Fprintf(os.Stderr, "%v\n", err)
+               os.Exit(1)
+       }
 }
diff --git a/go.mod b/go.mod
index 0c73e66e..a3d7d09f 100644
--- a/go.mod
+++ b/go.mod
@@ -26,8 +26,11 @@ require (
        github.com/golang/mock v1.6.0
        github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
        github.com/mattbaird/jsonpatch v0.0.0-20200820163806-098863c1fc24
-       github.com/prometheus/client_golang v1.12.2
-       github.com/prometheus/common v0.32.1
+       github.com/prometheus/client_golang v1.14.0
+       github.com/prometheus/common v0.37.0
+       github.com/spf13/cobra v1.6.0
+       github.com/spf13/pflag v1.0.5
+       github.com/spf13/viper v1.7.1
        github.com/stretchr/testify v1.8.2
        github.com/tidwall/gjson v1.14.4
        go.uber.org/zap v1.24.0
@@ -38,7 +41,7 @@ require (
        k8s.io/api v0.26.1
        k8s.io/apimachinery v0.26.1
        k8s.io/client-go v0.26.1
-       k8s.io/utils v0.0.0-20221107191617-1a15be271d1d
+       k8s.io/utils v0.0.0-20221128185143-99ec85e7a448
        sigs.k8s.io/structured-merge-diff/v4 v4.2.3
 )
 
@@ -60,10 +63,11 @@ require (
        github.com/dubbogo/triple v1.1.8 // indirect
        github.com/emicklei/go-restful/v3 v3.9.0 // indirect
        github.com/evanphx/json-patch v4.12.0+incompatible // indirect
+       github.com/fsnotify/fsnotify v1.6.0 // indirect
        github.com/gin-contrib/sse v0.1.0 // indirect
        github.com/go-errors/errors v1.0.1 // indirect
-       github.com/go-kit/log v0.1.0 // indirect
-       github.com/go-logfmt/logfmt v0.5.0 // indirect
+       github.com/go-kit/log v0.2.0 // indirect
+       github.com/go-logfmt/logfmt v0.5.1 // indirect
        github.com/go-logr/logr v1.2.3 // indirect
        github.com/go-ole/go-ole v1.2.6 // indirect
        github.com/go-openapi/jsonpointer v0.19.5 // indirect
@@ -81,7 +85,9 @@ require (
        github.com/google/go-cmp v0.5.9 // indirect
        github.com/google/gofuzz v1.1.0 // indirect
        github.com/gorilla/websocket v1.4.2 // indirect
+       github.com/hashicorp/hcl v1.0.0 // indirect
        github.com/imdario/mergo v0.3.6 // indirect
+       github.com/inconshreveable/mousetrap v1.0.1 // indirect
        github.com/jinzhu/copier v0.3.5 // indirect
        github.com/jmespath/go-jmespath v0.4.0 // indirect
        github.com/josharian/intern v1.0.0 // indirect
@@ -93,7 +99,7 @@ require (
        github.com/mailru/easyjson v0.7.6 // indirect
        github.com/mattn/go-colorable v0.1.7 // indirect
        github.com/mattn/go-isatty v0.0.16 // indirect
-       github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
+       github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect
        github.com/mitchellh/copystructure v1.2.0 // indirect
        github.com/mitchellh/mapstructure v1.5.0 // indirect
        github.com/mitchellh/reflectwalk v1.0.2 // indirect
@@ -103,29 +109,35 @@ require (
        github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // 
indirect
        github.com/nacos-group/nacos-sdk-go v1.1.3 // indirect
        github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
+       github.com/onsi/ginkgo/v2 v2.6.0 // indirect
+       github.com/onsi/gomega v1.24.1 // indirect
        github.com/pelletier/go-toml v1.7.0 // indirect
        github.com/pelletier/go-toml/v2 v2.0.6 // indirect
        github.com/pkg/errors v0.9.1 // indirect
        github.com/pmezard/go-difflib v1.0.0 // indirect
-       github.com/prometheus/client_model v0.2.0 // indirect
-       github.com/prometheus/procfs v0.7.3 // indirect
+       github.com/prometheus/client_model v0.3.0 // indirect
+       github.com/prometheus/procfs v0.8.0 // indirect
        github.com/prometheus/statsd_exporter v0.21.0 // indirect
        github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b // 
indirect
        github.com/shirou/gopsutil v3.20.11+incompatible // indirect
-       github.com/spf13/pflag v1.0.5 // indirect
+       github.com/spf13/afero v1.2.2 // indirect
+       github.com/spf13/cast v1.3.0 // indirect
+       github.com/spf13/jwalterweatherman v1.0.0 // indirect
+       github.com/subosito/gotenv v1.2.0 // indirect
        github.com/tidwall/match v1.1.1 // indirect
        github.com/tidwall/pretty v1.2.1 // indirect
        github.com/ugorji/go/codec v1.2.7 // indirect
        go.opencensus.io v0.23.0 // indirect
        go.uber.org/atomic v1.10.0 // indirect
+       go.uber.org/goleak v1.2.0 // indirect
        go.uber.org/multierr v1.9.0 // indirect
        golang.org/x/crypto v0.1.0 // indirect
        golang.org/x/oauth2 v0.4.0 // indirect
-       golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
+       golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
        golang.org/x/sys v0.5.0 // indirect
        golang.org/x/term v0.5.0 // indirect
        golang.org/x/text v0.7.0 // indirect
-       golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
+       golang.org/x/time v0.3.0 // indirect
        google.golang.org/appengine v1.6.7 // indirect
        google.golang.org/genproto v0.0.0-20230221151758-ace64dc21148 // 
indirect
        gopkg.in/inf.v0 v0.9.1 // indirect
diff --git a/go.sum b/go.sum
index 95e56037..e3273fbe 100644
--- a/go.sum
+++ b/go.sum
@@ -145,6 +145,7 @@ github.com/coreos/pkg 
v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfc
 github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod 
h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
 github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod 
h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
 github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod 
h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
+github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod 
h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
 github.com/creack/pty v1.1.7/go.mod 
h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
 github.com/creack/pty v1.1.9/go.mod 
h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
 github.com/creack/pty v1.1.11/go.mod 
h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
@@ -204,8 +205,9 @@ github.com/franela/goreq 
v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2
 github.com/frankban/quicktest v1.10.0/go.mod 
h1:ui7WezCLWMWxVWr1GETZY3smRy0G4KWq9vcPtJmFl7Y=
 github.com/fsnotify/fsnotify v1.4.7/go.mod 
h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
 github.com/fsnotify/fsnotify v1.4.9/go.mod 
h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
-github.com/fsnotify/fsnotify v1.5.4 
h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
 github.com/fsnotify/fsnotify v1.5.4/go.mod 
h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
+github.com/fsnotify/fsnotify v1.6.0 
h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
+github.com/fsnotify/fsnotify v1.6.0/go.mod 
h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
 github.com/getsentry/raven-go v0.2.0/go.mod 
h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ=
 github.com/ghodss/yaml v1.0.0/go.mod 
h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
 github.com/gin-contrib/sse v0.1.0 
h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
@@ -222,14 +224,16 @@ github.com/go-gl/glfw/v3.3/glfw 
v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2
 github.com/go-kit/kit v0.8.0/go.mod 
h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
 github.com/go-kit/kit v0.9.0/go.mod 
h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
 github.com/go-kit/kit v0.10.0/go.mod 
h1:xUsJbQ/Fp4kEt7AFgCuvyX4a71u8h9jB8tj/ORgOZ7o=
-github.com/go-kit/log v0.1.0 h1:DGJh0Sm43HbOeYDNnVZFl8BvcYVvjD5bqYJvp0REbwQ=
 github.com/go-kit/log v0.1.0/go.mod 
h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
+github.com/go-kit/log v0.2.0 h1:7i2K3eKTos3Vc0enKCfnVcgHh2olr/MyfboYq7cAcFw=
+github.com/go-kit/log v0.2.0/go.mod 
h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0=
 github.com/go-ldap/ldap v3.0.2+incompatible/go.mod 
h1:qfd9rJvER9Q0/D/Sqn1DfHRoBp40uXYvFoEVrNEPqRc=
 github.com/go-ldap/ldap/v3 v3.1.10/go.mod 
h1:5Zun81jBTabRaI8lzN7E1JjyEl1g6zI6u9pd8luAK4Q=
 github.com/go-logfmt/logfmt v0.3.0/go.mod 
h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
 github.com/go-logfmt/logfmt v0.4.0/go.mod 
h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
-github.com/go-logfmt/logfmt v0.5.0 
h1:TrB8swr/68K7m9CcGut2g3UOihhbcbiMAYiuTXdEih4=
 github.com/go-logfmt/logfmt v0.5.0/go.mod 
h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
+github.com/go-logfmt/logfmt v0.5.1 
h1:otpy5pqBCBZ1ng9RQ0dPu4PN7ba75Y/aA+UpowDyNVA=
+github.com/go-logfmt/logfmt v0.5.1/go.mod 
h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
 github.com/go-logr/logr v1.2.0/go.mod 
h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
 github.com/go-logr/logr v1.2.2/go.mod 
h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
 github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
@@ -257,7 +261,6 @@ github.com/go-playground/validator/v10 v10.11.1 
h1:prmOlTVv+YjZjmRmNSF3VmspqJIxJ
 github.com/go-playground/validator/v10 v10.11.1/go.mod 
h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU=
 github.com/go-resty/resty/v2 v2.7.0/go.mod 
h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I=
 github.com/go-sql-driver/mysql v1.4.0/go.mod 
h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
-github.com/go-stack/stack v1.8.0 
h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
 github.com/go-stack/stack v1.8.0/go.mod 
h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
 github.com/go-test/deep v1.0.2-0.20181118220953-042da051cf31/go.mod 
h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
 github.com/go-test/deep v1.0.2/go.mod 
h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
@@ -441,6 +444,8 @@ github.com/ianlancetaylor/demangle 
v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:
 github.com/imdario/mergo v0.3.6 h1:xTNEAn+kxVO7dTZGu0CegyqKZmoWFI0rF8UxjlB2d28=
 github.com/imdario/mergo v0.3.6/go.mod 
h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
 github.com/inconshreveable/mousetrap v1.0.0/go.mod 
h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
+github.com/inconshreveable/mousetrap v1.0.1 
h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc=
+github.com/inconshreveable/mousetrap v1.0.1/go.mod 
h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
 github.com/influxdata/influxdb1-client 
v0.0.0-20191209144304-8bf82d3c094d/go.mod 
h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
 github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869/go.mod 
h1:cJ6Cj7dQo+O6GJNiMx+Pa94qKj+TG8ONdKHgMNIyyag=
 github.com/jessevdk/go-flags v1.4.0/go.mod 
h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
@@ -530,8 +535,9 @@ github.com/mattn/go-isatty v0.0.14/go.mod 
h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k
 github.com/mattn/go-isatty v0.0.16 
h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
 github.com/mattn/go-isatty v0.0.16/go.mod 
h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
 github.com/mattn/go-runewidth v0.0.2/go.mod 
h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
-github.com/matttproud/golang_protobuf_extensions v1.0.1 
h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
 github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod 
h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
+github.com/matttproud/golang_protobuf_extensions v1.0.2 
h1:hAHbPm5IJGijwng3PWk09JkG9WeqChjprR5s9bBZ+OM=
+github.com/matttproud/golang_protobuf_extensions v1.0.2/go.mod 
h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
 github.com/miekg/dns v1.0.14/go.mod 
h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
 github.com/mitchellh/cli v1.0.0/go.mod 
h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
 github.com/mitchellh/copystructure v1.0.0/go.mod 
h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
@@ -588,11 +594,12 @@ github.com/oklog/run v1.0.0/go.mod 
h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQ
 github.com/oklog/ulid v1.3.1/go.mod 
h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
 github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod 
h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
 github.com/onsi/ginkgo v1.6.0/go.mod 
h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
-github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs=
 github.com/onsi/ginkgo v1.7.0/go.mod 
h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
-github.com/onsi/ginkgo/v2 v2.4.0 
h1:+Ig9nvqgS5OBSACXNk15PLdp0U9XPYROt9CFzVdFGIs=
+github.com/onsi/ginkgo/v2 v2.6.0 
h1:9t9b9vRUbFq3C4qKFCGkVuq/fIHji802N1nrtkh1mNc=
+github.com/onsi/ginkgo/v2 v2.6.0/go.mod 
h1:63DOGlLAH8+REH8jUGdL3YpCpu7JODesutUjdENfUAc=
 github.com/onsi/gomega v1.4.3/go.mod 
h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
-github.com/onsi/gomega v1.23.0 h1:/oxKu9c2HVap+F3PfKort2Hw5DEU+HGlW8n+tguWsys=
+github.com/onsi/gomega v1.24.1 h1:KORJXNNTzJXzu4ScJWssJfJMnJ+2QJqhoQSRwNlze9E=
+github.com/onsi/gomega v1.24.1/go.mod 
h1:3AOiACssS3/MajrniINInwbfOOtfZvplPzuRSmvt1jM=
 github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod 
h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
 github.com/opentracing-contrib/go-observer 
v0.0.0-20170622124052-a52f23424492/go.mod 
h1:Ngi6UdF0k5OKD5t5wlmGhe/EDKPoUM3BXZSSfIuJbis=
 github.com/opentracing/basictracer-go v1.0.0/go.mod 
h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74=
@@ -638,15 +645,17 @@ github.com/prometheus/client_golang v1.9.0/go.mod 
h1:FqZLKOZnGdFAhOK4nqGHa7D66Id
 github.com/prometheus/client_golang v1.11.0/go.mod 
h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0=
 github.com/prometheus/client_golang v1.11.1/go.mod 
h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0=
 github.com/prometheus/client_golang v1.12.1/go.mod 
h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY=
-github.com/prometheus/client_golang v1.12.2 
h1:51L9cDoUHVrXx4zWYlcLQIZ+d+VXHgqnYKkIuq4g/34=
 github.com/prometheus/client_golang v1.12.2/go.mod 
h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY=
+github.com/prometheus/client_golang v1.14.0 
h1:nJdhIvne2eSX/XRAFV9PcvFFRbrjbcTUj0VP62TMhnw=
+github.com/prometheus/client_golang v1.14.0/go.mod 
h1:8vpkKitgIVNcqrRBWh1C4TIUQgYNtG/XQE4E/Zae36Y=
 github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod 
h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
 github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod 
h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
 github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod 
h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
 github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod 
h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
 github.com/prometheus/client_model v0.1.0/go.mod 
h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
-github.com/prometheus/client_model v0.2.0 
h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M=
 github.com/prometheus/client_model v0.2.0/go.mod 
h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
+github.com/prometheus/client_model v0.3.0 
h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4=
+github.com/prometheus/client_model v0.3.0/go.mod 
h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w=
 github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod 
h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
 github.com/prometheus/common v0.2.0/go.mod 
h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
 github.com/prometheus/common v0.4.0/go.mod 
h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
@@ -657,8 +666,9 @@ github.com/prometheus/common v0.10.0/go.mod 
h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB8
 github.com/prometheus/common v0.15.0/go.mod 
h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s=
 github.com/prometheus/common v0.26.0/go.mod 
h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc=
 github.com/prometheus/common v0.28.0/go.mod 
h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls=
-github.com/prometheus/common v0.32.1 
h1:hWIdL3N2HoUx3B8j3YN9mWor0qhY/NlEKZEaXxuIRh4=
 github.com/prometheus/common v0.32.1/go.mod 
h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls=
+github.com/prometheus/common v0.37.0 
h1:ccBbHCgIiT9uSoFY0vX8H3zsNR5eLt17/RQLUvn8pXE=
+github.com/prometheus/common v0.37.0/go.mod 
h1:phzohg0JFMnBEFGxTDbfu3QyL5GI8gTQJFhYO5B3mfA=
 github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod 
h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
 github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod 
h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
 github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod 
h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
@@ -667,8 +677,9 @@ github.com/prometheus/procfs v0.0.8/go.mod 
h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+Gx
 github.com/prometheus/procfs v0.1.3/go.mod 
h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
 github.com/prometheus/procfs v0.2.0/go.mod 
h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
 github.com/prometheus/procfs v0.6.0/go.mod 
h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
-github.com/prometheus/procfs v0.7.3 
h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU=
 github.com/prometheus/procfs v0.7.3/go.mod 
h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
+github.com/prometheus/procfs v0.8.0 
h1:ODq8ZFEaYeCaZOJlZZdJA2AbQR98dSHSM1KW/You5mo=
+github.com/prometheus/procfs v0.8.0/go.mod 
h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0uaxHdg830/4=
 github.com/prometheus/statsd_exporter v0.21.0 
h1:hA05Q5RFeIjgwKIYEdFd59xu5Wwaznf33yKI+pyX6T8=
 github.com/prometheus/statsd_exporter v0.21.0/go.mod 
h1:rbT83sZq2V+p73lHhPZfMc3MLCHmSHelCh9hSGYNLTQ=
 github.com/prometheus/tsdb v0.7.1/go.mod 
h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
@@ -682,6 +693,7 @@ github.com/rogpeppe/go-internal v1.6.1/go.mod 
h1:xXDCJY+GAPziupqXw64V24skbSoqbTE
 github.com/rogpeppe/go-internal v1.8.0 
h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
 github.com/rogpeppe/go-internal v1.8.0/go.mod 
h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
 github.com/russross/blackfriday/v2 v2.0.1/go.mod 
h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
+github.com/russross/blackfriday/v2 v2.1.0/go.mod 
h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
 github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod 
h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
 github.com/ryanuber/columnize v2.1.0+incompatible/go.mod 
h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
 github.com/ryanuber/go-glob v1.0.0/go.mod 
h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
@@ -714,6 +726,8 @@ github.com/spf13/cast v1.3.0 
h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8=
 github.com/spf13/cast v1.3.0/go.mod 
h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
 github.com/spf13/cobra v0.0.3/go.mod 
h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
 github.com/spf13/cobra v1.1.1/go.mod 
h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI=
+github.com/spf13/cobra v1.6.0 h1:42a0n6jwCot1pUmomAp4T7DeMD+20LFv4Q54pxLf2LI=
+github.com/spf13/cobra v1.6.0/go.mod 
h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
 github.com/spf13/jwalterweatherman v1.0.0 
h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk=
 github.com/spf13/jwalterweatherman v1.0.0/go.mod 
h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
 github.com/spf13/pflag v1.0.1/go.mod 
h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
@@ -812,8 +826,9 @@ go.uber.org/atomic v1.9.0/go.mod 
h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
 go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
 go.uber.org/atomic v1.10.0/go.mod 
h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
 go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod 
h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
-go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
 go.uber.org/goleak v1.1.11/go.mod 
h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
+go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk=
+go.uber.org/goleak v1.2.0/go.mod 
h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo=
 go.uber.org/multierr v1.1.0/go.mod 
h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
 go.uber.org/multierr v1.3.0/go.mod 
h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
 go.uber.org/multierr v1.5.0/go.mod 
h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
@@ -927,6 +942,8 @@ golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod 
h1:9nx3DQGgdP8bBQD5qx
 golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod 
h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
 golang.org/x/net v0.0.0-20211105192438-b53810dc28af/go.mod 
h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
 golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod 
h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
+golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod 
h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
+golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod 
h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
 golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
 golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
 golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod 
h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
@@ -936,6 +953,7 @@ golang.org/x/oauth2 
v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4Iltr
 golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod 
h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
 golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod 
h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
 golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8/go.mod 
h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
+golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b/go.mod 
h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc=
 golang.org/x/oauth2 v0.4.0 h1:NF0gk8LVPg1Ml7SSbGyySuoxdsXitj7TvgvuRxIMc/M=
 golang.org/x/oauth2 v0.4.0/go.mod 
h1:RznEsdpjGAINPTOF0UH/t+xJ75L18YO3Ho6Pyn+uRec=
 golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod 
h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -948,8 +966,9 @@ golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod 
h1:RxMgew5VJxzue5/jJ
 golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod 
h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod 
h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod 
h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
-golang.org/x/sync v0.0.0-20210220032951-036812b2e83c 
h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
 golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod 
h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 
h1:uVc8UZUe6tr40fFVnUP5Oj+veunVezqYl9z7DYw9xzw=
+golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod 
h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod 
h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod 
h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod 
h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -1015,12 +1034,15 @@ golang.org/x/sys 
v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc
 golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod 
h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.0.0-20211106132015-ebca88c72f68/go.mod 
h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.0.0-20211117180635-dee7805ff2e1/go.mod 
h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod 
h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod 
h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod 
h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod 
h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod 
h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
 golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod 
h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
+golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod 
h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
 golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY=
 golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
 golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod 
h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -1040,8 +1062,8 @@ golang.org/x/time 
v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxb
 golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod 
h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
 golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e/go.mod 
h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
 golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod 
h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
-golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 
h1:vVKdlvoWBphwdxWKrFZEuM0kGgGLxUOYcY4U/2Vjg44=
-golang.org/x/time v0.0.0-20220210224613-90d013bbcef8/go.mod 
h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
+golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
+golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
 golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod 
h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod 
h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod 
h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
@@ -1277,8 +1299,8 @@ k8s.io/klog/v2 v2.80.1 
h1:atnLQ121W371wYYFawwYx1aEY2eUfs4l3J72wtgAwV4=
 k8s.io/klog/v2 v2.80.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
 k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 
h1:+70TFaan3hfJzs+7VK2o+OGxg8HsuBr/5f6tVAjDu6E=
 k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280/go.mod 
h1:+Axhij7bCpeqhklhUTe3xmOn6bWxolyZEeyaFpjGtl4=
-k8s.io/utils v0.0.0-20221107191617-1a15be271d1d 
h1:0Smp/HP1OH4Rvhe+4B8nWGERtlqAGSftbSbbmm45oFs=
-k8s.io/utils v0.0.0-20221107191617-1a15be271d1d/go.mod 
h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
+k8s.io/utils v0.0.0-20221128185143-99ec85e7a448 
h1:KTgPnR10d5zhztWptI952TNtt/4u5h3IzDXkdIMuo2Y=
+k8s.io/utils v0.0.0-20221128185143-99ec85e7a448/go.mod 
h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
 rsc.io/binaryregexp v0.2.0/go.mod 
h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
 rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
 rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
diff --git a/pkg/authority/config/envflag.go b/pkg/authority/config/envflag.go
deleted file mode 100644
index 2af3d468..00000000
--- a/pkg/authority/config/envflag.go
+++ /dev/null
@@ -1,116 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one or more
-// contributor license agreements.  See the NOTICE file distributed with
-// this work for additional information regarding copyright ownership.
-// The ASF licenses this file to You under the Apache License, Version 2.0
-// (the "License"); you may not use this file except in compliance with
-// the License.  You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package config
-
-import (
-       "crypto/rand"
-       "encoding/base32"
-       "flag"
-       "fmt"
-       "os"
-       "strconv"
-)
-
-func GetOptions() *Options {
-       // TODO read options from env
-       options := Options{
-               Namespace:   GetStringEnv("namespace", "dubbo-system"),
-               ServiceName: GetStringEnv("servicename", "dubbo-ca"),
-
-               PlainServerPort:  GetIntEnv("plainserverport", 30060),
-               SecureServerPort: GetIntEnv("secureserverport", 30062),
-               DebugPort:        GetIntEnv("debugport", 30070),
-
-               WebhookPort:       30080,
-               WebhookAllowOnErr: GetBoolEnv("webhookallowonerr", true),
-
-               CaValidity:   30 * 24 * 60 * 60 * 1000, // 30 day
-               CertValidity: 1 * 60 * 60 * 1000,       // 1 hour
-
-               InPodEnv:              GetBoolEnv("inpodenv", false),
-               IsKubernetesConnected: GetBoolEnv("iskubernetesconnected", 
false),
-               IsTrustAnyone:         GetBoolEnv("istrustanyone", false),
-               EnableOIDCCheck:       GetBoolEnv("enableoidccheck", true),
-               ResourcelockIdentity:  GetStringEnv("POD_NAME", 
GetDefaultResourcelockIdentity()),
-       }
-
-       flag.StringVar(&options.Namespace, "namespace", options.Namespace, 
"dubbo namespace")
-       flag.StringVar(&options.ServiceName, "servicename", 
options.ServiceName, "dubbo serviceName")
-       flag.IntVar(&options.PlainServerPort, "plainserverport", 
options.PlainServerPort, "dubbo plainServerPort")
-       flag.IntVar(&options.SecureServerPort, "secureserverport", 
options.SecureServerPort, "dubbo secureServerPort")
-       flag.IntVar(&options.DebugPort, "debugport", options.DebugPort, "dubbo 
debugPort")
-       webhookport := GetIntEnv("webhookport", 30080)
-       flag.IntVar(&webhookport, "webhookport", webhookport, "dubbo 
webhookPort")
-       flag.BoolVar(&options.WebhookAllowOnErr, "webhookallowonerr", 
options.WebhookAllowOnErr, "dubbo webhookAllowOnErr")
-       flag.BoolVar(&options.InPodEnv, "inpodenv", options.InPodEnv, "dubbo 
inPodEnv")
-       flag.BoolVar(&options.IsKubernetesConnected, "iskubernetesconnected", 
options.IsKubernetesConnected, "dubbo isKubernetesConnected")
-       flag.BoolVar(&options.EnableOIDCCheck, "enableoidccheck", 
options.EnableOIDCCheck, "dubbo enableOIDCCheck")
-       flag.Parse()
-
-       options.WebhookPort = int32(webhookport)
-       return &options
-}
-
-func GetStringEnv(name string, defvalue string) string {
-       val, ex := os.LookupEnv(name)
-       if ex {
-               return val
-       } else {
-               return defvalue
-       }
-}
-
-func GetIntEnv(name string, defvalue int) int {
-       val, ex := os.LookupEnv(name)
-       if ex {
-               num, err := strconv.Atoi(val)
-               if err != nil {
-                       return defvalue
-               } else {
-                       return num
-               }
-       } else {
-               return defvalue
-       }
-}
-
-func GetBoolEnv(name string, defvalue bool) bool {
-       val, ex := os.LookupEnv(name)
-       if ex {
-               boolVal, err := strconv.ParseBool(val)
-               if err != nil {
-                       return defvalue
-               } else {
-                       return boolVal
-               }
-       } else {
-               return defvalue
-       }
-}
-
-func GetDefaultResourcelockIdentity() string {
-       hostname, err := os.Hostname()
-       if err != nil {
-               panic(err)
-       }
-       randomBytes := make([]byte, 5)
-       _, err = rand.Read(randomBytes)
-       if err != nil {
-               panic(err)
-       }
-       randomStr := base32.StdEncoding.EncodeToString(randomBytes)
-       return fmt.Sprintf("%s-%s", hostname, randomStr)
-}
diff --git a/pkg/authority/config/options.go b/pkg/authority/config/options.go
index d714be98..db595da4 100644
--- a/pkg/authority/config/options.go
+++ b/pkg/authority/config/options.go
@@ -15,6 +15,16 @@
 
 package config
 
+import (
+       "crypto/rand"
+       "encoding/base32"
+       "fmt"
+       "os"
+       "strconv"
+
+       "github.com/spf13/pflag"
+)
+
 type Options struct {
        Namespace   string
        ServiceName string
@@ -37,3 +47,91 @@ type Options struct {
        EnableOIDCCheck      bool
        ResourcelockIdentity string
 }
+
+func NewOptions() *Options {
+       return &Options{
+               Namespace:         "dubbo-system",
+               ServiceName:       "dubbo-ca",
+               PlainServerPort:   30060,
+               SecureServerPort:  30062,
+               DebugPort:         30070,
+               WebhookPort:       30080,
+               WebhookAllowOnErr: true,
+               CaValidity:        30 * 24 * 60 * 60 * 1000, // 30 day
+               CertValidity:      1 * 60 * 60 * 1000,       // 1 hour
+
+               InPodEnv:              false,
+               IsKubernetesConnected: false,
+               EnableOIDCCheck:       true,
+               ResourcelockIdentity:  GetStringEnv("POD_NAME", 
GetDefaultResourcelockIdentity()),
+       }
+}
+
+func (o *Options) FillFlags(flags *pflag.FlagSet) {
+       flags.StringVar(&o.Namespace, "namespace", "dubbo-system", "dubbo 
namespace")
+       flags.StringVar(&o.ServiceName, "service-name", "dubbo-ca", "dubbo 
service name")
+       flags.IntVar(&o.PlainServerPort, "plain-server-port", 30060, "dubbo 
plain server port")
+       flags.IntVar(&o.SecureServerPort, "secure-server-port", 30062, "dubbo 
secure server port")
+       flags.IntVar(&o.DebugPort, "debug-port", 30070, "dubbo debug port")
+       flags.Int32Var(&o.WebhookPort, "webhook-port", 30080, "dubbo webhook 
port")
+       flags.BoolVar(&o.WebhookAllowOnErr, "webhook-allow-on-err", true, 
"dubbo webhook allow on error")
+       flags.BoolVar(&o.InPodEnv, "in-pod-env", false, "dubbo run in pod 
environment")
+       flags.BoolVar(&o.IsKubernetesConnected, "is-kubernetes-connected", 
false, "dubbo connected with kubernetes")
+       flags.BoolVar(&o.EnableOIDCCheck, "enable-oidc-check", false, "dubbo 
enable OIDC check")
+}
+
+func (o *Options) Validate() []error {
+       // TODO validate options
+       return nil
+}
+
+func GetStringEnv(name string, defvalue string) string {
+       val, ex := os.LookupEnv(name)
+       if ex {
+               return val
+       } else {
+               return defvalue
+       }
+}
+
+func GetIntEnv(name string, defvalue int) int {
+       val, ex := os.LookupEnv(name)
+       if ex {
+               num, err := strconv.Atoi(val)
+               if err != nil {
+                       return defvalue
+               } else {
+                       return num
+               }
+       } else {
+               return defvalue
+       }
+}
+
+func GetBoolEnv(name string, defvalue bool) bool {
+       val, ex := os.LookupEnv(name)
+       if ex {
+               boolVal, err := strconv.ParseBool(val)
+               if err != nil {
+                       return defvalue
+               } else {
+                       return boolVal
+               }
+       } else {
+               return defvalue
+       }
+}
+
+func GetDefaultResourcelockIdentity() string {
+       hostname, err := os.Hostname()
+       if err != nil {
+               panic(err)
+       }
+       randomBytes := make([]byte, 5)
+       _, err = rand.Read(randomBytes)
+       if err != nil {
+               panic(err)
+       }
+       randomStr := base32.StdEncoding.EncodeToString(randomBytes)
+       return fmt.Sprintf("%s-%s", hostname, randomStr)
+}
diff --git a/pkg/authority/k8s/client.go b/pkg/authority/k8s/client.go
index 5621d5bb..b697dc67 100644
--- a/pkg/authority/k8s/client.go
+++ b/pkg/authority/k8s/client.go
@@ -18,6 +18,7 @@ package k8s
 import (
        "context"
        "flag"
+       "os"
        "path/filepath"
        "reflect"
        "strings"
@@ -44,6 +45,13 @@ import (
        "k8s.io/client-go/util/homedir"
 )
 
+var kubeconfig string
+
+func init() {
+       flag.StringVar(&kubeconfig, "kubeconfig", "",
+               "Paths to a kubeconfig. Only required if out-of-cluster.")
+}
+
 type Client interface {
        Init(options *config.Options) bool
        GetAuthorityCert(namespace string) (string, string)
@@ -72,17 +80,20 @@ func (c *ClientImpl) Init(options *config.Options) bool {
        options.InPodEnv = err == nil
        if err != nil {
                logger.Sugar().Infof("Failed to load config from Pod. Will fall 
back to kube config file.")
-
-               var kubeconfig *string
-               if home := homedir.HomeDir(); home != "" {
-                       kubeconfig = flag.String("kubeconfig", 
filepath.Join(home, ".kube", "config"), "(optional) absolute path to the 
kubeconfig file")
-               } else {
-                       kubeconfig = flag.String("kubeconfig", "", "absolute 
path to the kubeconfig file")
+               // Read kubeconfig from command line
+               if len(kubeconfig) <= 0 {
+                       // Read kubeconfig from env
+                       kubeconfig = 
os.Getenv(clientcmd.RecommendedConfigPathEnvVar)
+                       if len(kubeconfig) <= 0 {
+                               // Read kubeconfig from home dir
+                               if home := homedir.HomeDir(); home != "" {
+                                       kubeconfig = filepath.Join(home, 
".kube", "config")
+                               }
+                       }
                }
-               flag.Parse()
-
                // use the current context in kubeconfig
-               config, err = clientcmd.BuildConfigFromFlags("", *kubeconfig)
+               logger.Sugar().Infof("Read kubeconfig from %s", kubeconfig)
+               config, err = clientcmd.BuildConfigFromFlags("", kubeconfig)
                if err != nil {
                        logger.Sugar().Warnf("Failed to load config from kube 
config file.")
                        return false


Reply via email to