Skip to content

Commit

Permalink
refactor to prepare for struct logs (#6501)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexFenlon authored Sep 26, 2024
1 parent 4a0d5b5 commit 4ee3676
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 57 deletions.
114 changes: 58 additions & 56 deletions cmd/nginx-ingress/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,50 +217,12 @@ var (
func parseFlags() {
flag.Parse()

if *versionFlag {
if *versionFlag { // printed in main
os.Exit(0)
}
}

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")
}

func initValidate() {
if *enableLatencyMetrics && !*enablePrometheusMetrics {
glog.Warning("enable-latency-metrics flag requires enable-prometheus-metrics, latency metrics will not be collected")
*enableLatencyMetrics = false
Expand All @@ -271,26 +233,14 @@ func parseFlags() {
*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")
}
mustValidateInitialChecks()
mustValidateWatchedNamespaces()
mustValidateFlags()
}

func mustValidateInitialChecks() {
Expand Down Expand Up @@ -402,6 +352,58 @@ 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 *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 *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
Expand Down
2 changes: 1 addition & 1 deletion cmd/nginx-ingress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ const (
func main() {
commitHash, commitTime, dirtyBuild := getBuildInfo()
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()
initValidate()
parsedFlags := os.Args[1:]

buildOS := os.Getenv("BUILD_OS")
Expand Down

0 comments on commit 4ee3676

Please sign in to comment.