Skip to content

Commit

Permalink
Replace flag with pflag
Browse files Browse the repository at this point in the history
Signed-off-by: Aniruddha Basak <aniruddha.basak@syself.com>
  • Loading branch information
aniruddha2000 committed Oct 17, 2023
1 parent 941edbb commit 3ac8269
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require (
github.com/onsi/gomega v1.27.6
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.2
go.uber.org/zap v1.24.0
golang.org/x/crypto v0.8.0
Expand Down Expand Up @@ -107,7 +108,6 @@ require (
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.15.0 // indirect
github.com/stoewer/go-strcase v1.2.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
Expand Down
48 changes: 26 additions & 22 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ limitations under the License.
package main

import (
"flag"
"fmt"
"os"
"sync"
Expand All @@ -27,6 +26,7 @@ import (
"github.com/hivelocity/cluster-api-provider-hivelocity/controllers"
hvclient "github.com/hivelocity/cluster-api-provider-hivelocity/pkg/services/hivelocity/client"
"github.com/hivelocity/cluster-api-provider-hivelocity/pkg/utils"
"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
Expand All @@ -52,28 +52,32 @@ func init() {
//+kubebuilder:scaffold:scheme
}

var (
metricsAddr string
enableLeaderElection bool
leaderElectionNamespace string
probeAddr string
watchFilterValue string
watchNamespace string
hivelocityClusterConcurrency int
hivelocityMachineConcurrency int
logLevel string
)

func main() {
var metricsAddr string
var enableLeaderElection bool
var leaderElectionNamespace string
var probeAddr string
var watchFilterValue string
var watchNamespace string
var hivelocityClusterConcurrency int
var hivelocityMachineConcurrency int
var logLevel string

flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "leader-elect", true, "Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.")
flag.StringVar(&leaderElectionNamespace, "leader-elect-namespace", "", "Namespace that the controller performs leader election in. If unspecified, the controller will discover which namespace it is running in.")
flag.IntVar(&hivelocityClusterConcurrency, "hivelocitycluster-concurrency", 1, "Number of HivelocityClusters to process simultaneously")
flag.IntVar(&hivelocityMachineConcurrency, "hivelocitymachine-concurrency", 1, "Number of HivelocityMachines to process simultaneously")
flag.StringVar(&watchFilterValue, "watch-filter", "", fmt.Sprintf("Label value that the controller watches to reconcile cluster-api objects. Label key is always %s. If unspecified, the controller watches for all cluster-api objects.", clusterv1.WatchLabel))
flag.StringVar(&watchNamespace, "namespace", "", "Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.")
flag.StringVar(&logLevel, "log-level", "debug", "Specifies log level. Options are 'debug', 'info' and 'error'")

flag.Parse()
fs := pflag.CommandLine

fs.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
fs.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
fs.BoolVar(&enableLeaderElection, "leader-elect", true, "Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.")
fs.StringVar(&leaderElectionNamespace, "leader-elect-namespace", "", "Namespace that the controller performs leader election in. If unspecified, the controller will discover which namespace it is running in.")
fs.IntVar(&hivelocityClusterConcurrency, "hivelocitycluster-concurrency", 1, "Number of HivelocityClusters to process simultaneously")
fs.IntVar(&hivelocityMachineConcurrency, "hivelocitymachine-concurrency", 1, "Number of HivelocityMachines to process simultaneously")
fs.StringVar(&watchFilterValue, "watch-filter", "", fmt.Sprintf("Label value that the controller watches to reconcile cluster-api objects. Label key is always %s. If unspecified, the controller watches for all cluster-api objects.", clusterv1.WatchLabel))
fs.StringVar(&watchNamespace, "namespace", "", "Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.")
fs.StringVar(&logLevel, "log-level", "debug", "Specifies log level. Options are 'debug', 'info' and 'error'")

pflag.Parse()

ctrl.SetLogger(utils.GetDefaultLogger(logLevel))

Expand Down

0 comments on commit 3ac8269

Please sign in to comment.