From 3c0aea990751c2925aaebf188b56ceef14d9454a Mon Sep 17 00:00:00 2001 From: Alex Fenlon Date: Wed, 25 Sep 2024 11:01:03 +0100 Subject: [PATCH] refactor to prepare for struct logs --- cmd/nginx-ingress/flags.go | 136 +++++++++++++++++++------------------ cmd/nginx-ingress/main.go | 1 + 2 files changed, 70 insertions(+), 67 deletions(-) diff --git a/cmd/nginx-ingress/flags.go b/cmd/nginx-ingress/flags.go index 587eca2cd6..cb59f064cc 100644 --- a/cmd/nginx-ingress/flags.go +++ b/cmd/nginx-ingress/flags.go @@ -220,77 +220,12 @@ func parseFlags() { if *versionFlag { os.Exit(0) } +} +func initValidation() { mustValidateInitialChecks() mustValidateWatchedNamespaces() mustValidateFlags() - - if *enableTLSPassthrough && !*enableCustomResources { - glog.Fatal("enable-tls-passthrough flag requires -enable-custom-resources") - } - - if *appProtect && !*nginxPlus { - glog.Fatal("NGINX App Protect support is for NGINX Plus only") - } - - if *appProtectLogLevel != appProtectLogLevelDefault && !*appProtect && !*nginxPlus { - glog.Fatal("app-protect-log-level support is for NGINX Plus only and App Protect is enable") - } - - if *appProtectDos && !*nginxPlus { - glog.Fatal("NGINX App Protect Dos support is for NGINX Plus only") - } - - if *appProtectDosDebug && !*appProtectDos && !*nginxPlus { - glog.Fatal("NGINX App Protect Dos debug support is for NGINX Plus only and App Protect Dos is enable") - } - - if *appProtectDosMaxDaemons != 0 && !*appProtectDos && !*nginxPlus { - glog.Fatal("NGINX App Protect Dos max daemons support is for NGINX Plus only and App Protect Dos is enable") - } - - if *appProtectDosMaxWorkers != 0 && !*appProtectDos && !*nginxPlus { - glog.Fatal("NGINX App Protect Dos max workers support is for NGINX Plus and App Protect Dos is enable") - } - - if *appProtectDosMemory != 0 && !*appProtectDos && !*nginxPlus { - glog.Fatal("NGINX App Protect Dos memory support is for NGINX Plus and App Protect Dos is enable") - } - - if *enableInternalRoutes && *spireAgentAddress == "" { - glog.Fatal("enable-internal-routes flag requires spire-agent-address") - } - - if *enableLatencyMetrics && !*enablePrometheusMetrics { - glog.Warning("enable-latency-metrics flag requires enable-prometheus-metrics, latency metrics will not be collected") - *enableLatencyMetrics = false - } - - if *enableServiceInsight && !*nginxPlus { - glog.Warning("enable-service-insight flag support is for NGINX Plus, service insight endpoint will not be exposed") - *enableServiceInsight = false - } - - if *enableCertManager && !*enableCustomResources { - glog.Fatal("enable-cert-manager flag requires -enable-custom-resources") - } - - if *enableExternalDNS && !*enableCustomResources { - glog.Fatal("enable-external-dns flag requires -enable-custom-resources") - } - - if *ingressLink != "" && *externalService != "" { - glog.Fatal("ingresslink and external-service cannot both be set") - } - - if *enableDynamicWeightChangesReload && !*nginxPlus { - glog.Warning("weight-changes-dynamic-reload flag support is for NGINX Plus, Dynamic Weight Changes will not be enabled") - *enableDynamicWeightChangesReload = false - } - - if *agent && !*appProtect { - glog.Fatal("NGINX Agent is used to enable the Security Monitoring dashboard and requires NGINX App Protect to be enabled") - } } func mustValidateInitialChecks() { @@ -402,6 +337,73 @@ func mustValidateFlags() { glog.Fatalf("Invalid value for app-protect-log-level: %v", *appProtectLogLevel) } } + + if *enableTLSPassthrough && !*enableCustomResources { + glog.Fatal("enable-tls-passthrough flag requires -enable-custom-resources") + } + + if *appProtect && !*nginxPlus { + glog.Fatal("NGINX App Protect support is for NGINX Plus only") + } + + if *appProtectLogLevel != appProtectLogLevelDefault && !*appProtect && !*nginxPlus { + glog.Fatal("app-protect-log-level support is for NGINX Plus only and App Protect is enable") + } + + if *appProtectDos && !*nginxPlus { + glog.Fatal("NGINX App Protect Dos support is for NGINX Plus only") + } + + if *appProtectDosDebug && !*appProtectDos && !*nginxPlus { + glog.Fatal("NGINX App Protect Dos debug support is for NGINX Plus only and App Protect Dos is enable") + } + + if *appProtectDosMaxDaemons != 0 && !*appProtectDos && !*nginxPlus { + glog.Fatal("NGINX App Protect Dos max daemons support is for NGINX Plus only and App Protect Dos is enable") + } + + if *appProtectDosMaxWorkers != 0 && !*appProtectDos && !*nginxPlus { + glog.Fatal("NGINX App Protect Dos max workers support is for NGINX Plus and App Protect Dos is enable") + } + + if *appProtectDosMemory != 0 && !*appProtectDos && !*nginxPlus { + glog.Fatal("NGINX App Protect Dos memory support is for NGINX Plus and App Protect Dos is enable") + } + + if *enableInternalRoutes && *spireAgentAddress == "" { + glog.Fatal("enable-internal-routes flag requires spire-agent-address") + } + + if *enableLatencyMetrics && !*enablePrometheusMetrics { + glog.Warning("enable-latency-metrics flag requires enable-prometheus-metrics, latency metrics will not be collected") + *enableLatencyMetrics = false + } + + if *enableServiceInsight && !*nginxPlus { + glog.Warning("enable-service-insight flag support is for NGINX Plus, service insight endpoint will not be exposed") + *enableServiceInsight = false + } + + if *enableCertManager && !*enableCustomResources { + glog.Fatal("enable-cert-manager flag requires -enable-custom-resources") + } + + if *enableExternalDNS && !*enableCustomResources { + glog.Fatal("enable-external-dns flag requires -enable-custom-resources") + } + + if *ingressLink != "" && *externalService != "" { + glog.Fatal("ingresslink and external-service cannot both be set") + } + + if *enableDynamicWeightChangesReload && !*nginxPlus { + glog.Warning("weight-changes-dynamic-reload flag support is for NGINX Plus, Dynamic Weight Changes will not be enabled") + *enableDynamicWeightChangesReload = false + } + + if *agent && !*appProtect { + glog.Fatal("NGINX Agent is used to enable the Security Monitoring dashboard and requires NGINX App Protect to be enabled") + } } // validateNamespaceNames validates the namespaces are in the correct format diff --git a/cmd/nginx-ingress/main.go b/cmd/nginx-ingress/main.go index ccb6dd77f9..a9e432548e 100644 --- a/cmd/nginx-ingress/main.go +++ b/cmd/nginx-ingress/main.go @@ -64,6 +64,7 @@ func main() { fmt.Printf("NGINX Ingress Controller Version=%v Commit=%v Date=%v DirtyState=%v Arch=%v/%v Go=%v\n", version, commitHash, commitTime, dirtyBuild, runtime.GOOS, runtime.GOARCH, runtime.Version()) parseFlags() + initValidation() parsedFlags := os.Args[1:] buildOS := os.Getenv("BUILD_OS")