@@ -39,68 +39,20 @@ var (
39
39
}
40
40
41
41
// Backing values for static subcommand cli flags.
42
- updateGCStatus bool
43
- disableMetrics bool
44
- metricsListenPort int
45
- metricsSecure bool
42
+ updateGCStatus bool
43
+ disableMetrics bool
44
+ metricsSecure bool
46
45
46
+ metricsListenPort = intValidatingValue {
47
+ validator : validatePort ,
48
+ value : 9113 ,
49
+ }
47
50
gateway = namespacedNameValue {}
48
51
configName = stringValidatingValue {
49
52
validator : validateResourceName ,
50
53
}
51
54
)
52
55
53
- // stringValidatingValue is a string flag value with custom validation logic.
54
- // it implements the pflag.Value interface.
55
- type stringValidatingValue struct {
56
- validator func (v string ) error
57
- value string
58
- }
59
-
60
- func (v * stringValidatingValue ) String () string {
61
- return v .value
62
- }
63
-
64
- func (v * stringValidatingValue ) Set (param string ) error {
65
- if err := v .validator (param ); err != nil {
66
- return err
67
- }
68
- v .value = param
69
- return nil
70
- }
71
-
72
- func (v * stringValidatingValue ) Type () string {
73
- return "string"
74
- }
75
-
76
- // namespacedNameValue is a string flag value that represents a namespaced name.
77
- // it implements the pflag.Value interface.
78
- type namespacedNameValue struct {
79
- value types.NamespacedName
80
- }
81
-
82
- func (v * namespacedNameValue ) String () string {
83
- if (v .value == types.NamespacedName {}) {
84
- // if we don't do that, the default value in the help message will be printed as "/"
85
- return ""
86
- }
87
- return v .value .String ()
88
- }
89
-
90
- func (v * namespacedNameValue ) Set (param string ) error {
91
- nsname , err := parseNamespacedResourceName (param )
92
- if err != nil {
93
- return err
94
- }
95
-
96
- v .value = nsname
97
- return nil
98
- }
99
-
100
- func (v * namespacedNameValue ) Type () string {
101
- return "string"
102
- }
103
-
104
56
func createRootCommand () * cobra.Command {
105
57
rootCmd := & cobra.Command {
106
58
Use : "gateway" ,
@@ -158,11 +110,8 @@ func createStaticModeCommand() *cobra.Command {
158
110
159
111
metricsConfig := config.MetricsConfig {}
160
112
if ! disableMetrics {
161
- if err := validatePort (metricsListenPort ); err != nil {
162
- return fmt .Errorf ("error validating metrics listen port: %w" , err )
163
- }
164
113
metricsConfig .Enabled = true
165
- metricsConfig .Port = metricsListenPort
114
+ metricsConfig .Port = metricsListenPort . value
166
115
metricsConfig .Secure = metricsSecure
167
116
}
168
117
@@ -219,10 +168,9 @@ func createStaticModeCommand() *cobra.Command {
219
168
"Disable exposing metrics in the Prometheus format." ,
220
169
)
221
170
222
- cmd .Flags ().IntVar (
171
+ cmd .Flags ().Var (
223
172
& metricsListenPort ,
224
173
"metrics-port" ,
225
- 9113 ,
226
174
"Set the port where the metrics are exposed. Format: [1023 - 65535]" ,
227
175
)
228
176
0 commit comments