@@ -217,50 +217,12 @@ var (
217217func parseFlags () {
218218 flag .Parse ()
219219
220- if * versionFlag {
220+ if * versionFlag { // printed in main
221221 os .Exit (0 )
222222 }
223+ }
223224
224- mustValidateInitialChecks ()
225- mustValidateWatchedNamespaces ()
226- mustValidateFlags ()
227-
228- if * enableTLSPassthrough && ! * enableCustomResources {
229- glog .Fatal ("enable-tls-passthrough flag requires -enable-custom-resources" )
230- }
231-
232- if * appProtect && ! * nginxPlus {
233- glog .Fatal ("NGINX App Protect support is for NGINX Plus only" )
234- }
235-
236- if * appProtectLogLevel != appProtectLogLevelDefault && ! * appProtect && ! * nginxPlus {
237- glog .Fatal ("app-protect-log-level support is for NGINX Plus only and App Protect is enable" )
238- }
239-
240- if * appProtectDos && ! * nginxPlus {
241- glog .Fatal ("NGINX App Protect Dos support is for NGINX Plus only" )
242- }
243-
244- if * appProtectDosDebug && ! * appProtectDos && ! * nginxPlus {
245- glog .Fatal ("NGINX App Protect Dos debug support is for NGINX Plus only and App Protect Dos is enable" )
246- }
247-
248- if * appProtectDosMaxDaemons != 0 && ! * appProtectDos && ! * nginxPlus {
249- glog .Fatal ("NGINX App Protect Dos max daemons support is for NGINX Plus only and App Protect Dos is enable" )
250- }
251-
252- if * appProtectDosMaxWorkers != 0 && ! * appProtectDos && ! * nginxPlus {
253- glog .Fatal ("NGINX App Protect Dos max workers support is for NGINX Plus and App Protect Dos is enable" )
254- }
255-
256- if * appProtectDosMemory != 0 && ! * appProtectDos && ! * nginxPlus {
257- glog .Fatal ("NGINX App Protect Dos memory support is for NGINX Plus and App Protect Dos is enable" )
258- }
259-
260- if * enableInternalRoutes && * spireAgentAddress == "" {
261- glog .Fatal ("enable-internal-routes flag requires spire-agent-address" )
262- }
263-
225+ func initValidate () {
264226 if * enableLatencyMetrics && ! * enablePrometheusMetrics {
265227 glog .Warning ("enable-latency-metrics flag requires enable-prometheus-metrics, latency metrics will not be collected" )
266228 * enableLatencyMetrics = false
@@ -271,26 +233,14 @@ func parseFlags() {
271233 * enableServiceInsight = false
272234 }
273235
274- if * enableCertManager && ! * enableCustomResources {
275- glog .Fatal ("enable-cert-manager flag requires -enable-custom-resources" )
276- }
277-
278- if * enableExternalDNS && ! * enableCustomResources {
279- glog .Fatal ("enable-external-dns flag requires -enable-custom-resources" )
280- }
281-
282- if * ingressLink != "" && * externalService != "" {
283- glog .Fatal ("ingresslink and external-service cannot both be set" )
284- }
285-
286236 if * enableDynamicWeightChangesReload && ! * nginxPlus {
287237 glog .Warning ("weight-changes-dynamic-reload flag support is for NGINX Plus, Dynamic Weight Changes will not be enabled" )
288238 * enableDynamicWeightChangesReload = false
289239 }
290240
291- if * agent && ! * appProtect {
292- glog . Fatal ( "NGINX Agent is used to enable the Security Monitoring dashboard and requires NGINX App Protect to be enabled" )
293- }
241+ mustValidateInitialChecks ()
242+ mustValidateWatchedNamespaces ( )
243+ mustValidateFlags ()
294244}
295245
296246func mustValidateInitialChecks () {
@@ -402,6 +352,58 @@ func mustValidateFlags() {
402352 glog .Fatalf ("Invalid value for app-protect-log-level: %v" , * appProtectLogLevel )
403353 }
404354 }
355+
356+ if * enableTLSPassthrough && ! * enableCustomResources {
357+ glog .Fatal ("enable-tls-passthrough flag requires -enable-custom-resources" )
358+ }
359+
360+ if * appProtect && ! * nginxPlus {
361+ glog .Fatal ("NGINX App Protect support is for NGINX Plus only" )
362+ }
363+
364+ if * appProtectLogLevel != appProtectLogLevelDefault && ! * appProtect && ! * nginxPlus {
365+ glog .Fatal ("app-protect-log-level support is for NGINX Plus only and App Protect is enable" )
366+ }
367+
368+ if * appProtectDos && ! * nginxPlus {
369+ glog .Fatal ("NGINX App Protect Dos support is for NGINX Plus only" )
370+ }
371+
372+ if * appProtectDosDebug && ! * appProtectDos && ! * nginxPlus {
373+ glog .Fatal ("NGINX App Protect Dos debug support is for NGINX Plus only and App Protect Dos is enable" )
374+ }
375+
376+ if * appProtectDosMaxDaemons != 0 && ! * appProtectDos && ! * nginxPlus {
377+ glog .Fatal ("NGINX App Protect Dos max daemons support is for NGINX Plus only and App Protect Dos is enable" )
378+ }
379+
380+ if * appProtectDosMaxWorkers != 0 && ! * appProtectDos && ! * nginxPlus {
381+ glog .Fatal ("NGINX App Protect Dos max workers support is for NGINX Plus and App Protect Dos is enable" )
382+ }
383+
384+ if * appProtectDosMemory != 0 && ! * appProtectDos && ! * nginxPlus {
385+ glog .Fatal ("NGINX App Protect Dos memory support is for NGINX Plus and App Protect Dos is enable" )
386+ }
387+
388+ if * enableInternalRoutes && * spireAgentAddress == "" {
389+ glog .Fatal ("enable-internal-routes flag requires spire-agent-address" )
390+ }
391+
392+ if * enableCertManager && ! * enableCustomResources {
393+ glog .Fatal ("enable-cert-manager flag requires -enable-custom-resources" )
394+ }
395+
396+ if * enableExternalDNS && ! * enableCustomResources {
397+ glog .Fatal ("enable-external-dns flag requires -enable-custom-resources" )
398+ }
399+
400+ if * ingressLink != "" && * externalService != "" {
401+ glog .Fatal ("ingresslink and external-service cannot both be set" )
402+ }
403+
404+ if * agent && ! * appProtect {
405+ glog .Fatal ("NGINX Agent is used to enable the Security Monitoring dashboard and requires NGINX App Protect to be enabled" )
406+ }
405407}
406408
407409// validateNamespaceNames validates the namespaces are in the correct format
0 commit comments