Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to prepare for structured logs #6501

Merged
merged 8 commits into from
Sep 26, 2024
136 changes: 69 additions & 67 deletions cmd/nginx-ingress/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,77 +220,12 @@
if *versionFlag {
AlexFenlon marked this conversation as resolved.
Show resolved Hide resolved
os.Exit(0)
}
}

func initValidation() {

Check warning on line 225 in cmd/nginx-ingress/flags.go

View check run for this annotation

Codecov / codecov/patch

cmd/nginx-ingress/flags.go#L225

Added line #L225 was not covered by tests
AlexFenlon marked this conversation as resolved.
Show resolved Hide resolved
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() {
Expand Down Expand Up @@ -402,6 +337,73 @@
glog.Fatalf("Invalid value for app-protect-log-level: %v", *appProtectLogLevel)
}
}

if *enableTLSPassthrough && !*enableCustomResources {
glog.Fatal("enable-tls-passthrough flag requires -enable-custom-resources")

Check warning on line 342 in cmd/nginx-ingress/flags.go

View check run for this annotation

Codecov / codecov/patch

cmd/nginx-ingress/flags.go#L341-L342

Added lines #L341 - L342 were not covered by tests
}

if *appProtect && !*nginxPlus {
glog.Fatal("NGINX App Protect support is for NGINX Plus only")

Check warning on line 346 in cmd/nginx-ingress/flags.go

View check run for this annotation

Codecov / codecov/patch

cmd/nginx-ingress/flags.go#L345-L346

Added lines #L345 - L346 were not covered by tests
}

if *appProtectLogLevel != appProtectLogLevelDefault && !*appProtect && !*nginxPlus {
glog.Fatal("app-protect-log-level support is for NGINX Plus only and App Protect is enable")

Check warning on line 350 in cmd/nginx-ingress/flags.go

View check run for this annotation

Codecov / codecov/patch

cmd/nginx-ingress/flags.go#L349-L350

Added lines #L349 - L350 were not covered by tests
}

if *appProtectDos && !*nginxPlus {
glog.Fatal("NGINX App Protect Dos support is for NGINX Plus only")

Check warning on line 354 in cmd/nginx-ingress/flags.go

View check run for this annotation

Codecov / codecov/patch

cmd/nginx-ingress/flags.go#L353-L354

Added lines #L353 - L354 were not covered by tests
}

if *appProtectDosDebug && !*appProtectDos && !*nginxPlus {
glog.Fatal("NGINX App Protect Dos debug support is for NGINX Plus only and App Protect Dos is enable")

Check warning on line 358 in cmd/nginx-ingress/flags.go

View check run for this annotation

Codecov / codecov/patch

cmd/nginx-ingress/flags.go#L357-L358

Added lines #L357 - L358 were not covered by tests
}

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

Check warning on line 362 in cmd/nginx-ingress/flags.go

View check run for this annotation

Codecov / codecov/patch

cmd/nginx-ingress/flags.go#L361-L362

Added lines #L361 - L362 were not covered by tests
}

if *appProtectDosMaxWorkers != 0 && !*appProtectDos && !*nginxPlus {
glog.Fatal("NGINX App Protect Dos max workers support is for NGINX Plus and App Protect Dos is enable")

Check warning on line 366 in cmd/nginx-ingress/flags.go

View check run for this annotation

Codecov / codecov/patch

cmd/nginx-ingress/flags.go#L365-L366

Added lines #L365 - L366 were not covered by tests
}

if *appProtectDosMemory != 0 && !*appProtectDos && !*nginxPlus {
glog.Fatal("NGINX App Protect Dos memory support is for NGINX Plus and App Protect Dos is enable")

Check warning on line 370 in cmd/nginx-ingress/flags.go

View check run for this annotation

Codecov / codecov/patch

cmd/nginx-ingress/flags.go#L369-L370

Added lines #L369 - L370 were not covered by tests
}

if *enableInternalRoutes && *spireAgentAddress == "" {
glog.Fatal("enable-internal-routes flag requires spire-agent-address")

Check warning on line 374 in cmd/nginx-ingress/flags.go

View check run for this annotation

Codecov / codecov/patch

cmd/nginx-ingress/flags.go#L373-L374

Added lines #L373 - L374 were not covered by tests
}

if *enableLatencyMetrics && !*enablePrometheusMetrics {
glog.Warning("enable-latency-metrics flag requires enable-prometheus-metrics, latency metrics will not be collected")
*enableLatencyMetrics = false

Check warning on line 379 in cmd/nginx-ingress/flags.go

View check run for this annotation

Codecov / codecov/patch

cmd/nginx-ingress/flags.go#L377-L379

Added lines #L377 - L379 were not covered by tests
}

if *enableServiceInsight && !*nginxPlus {
glog.Warning("enable-service-insight flag support is for NGINX Plus, service insight endpoint will not be exposed")
*enableServiceInsight = false

Check warning on line 384 in cmd/nginx-ingress/flags.go

View check run for this annotation

Codecov / codecov/patch

cmd/nginx-ingress/flags.go#L382-L384

Added lines #L382 - L384 were not covered by tests
}
AlexFenlon marked this conversation as resolved.
Show resolved Hide resolved

if *enableCertManager && !*enableCustomResources {
glog.Fatal("enable-cert-manager flag requires -enable-custom-resources")

Check warning on line 388 in cmd/nginx-ingress/flags.go

View check run for this annotation

Codecov / codecov/patch

cmd/nginx-ingress/flags.go#L387-L388

Added lines #L387 - L388 were not covered by tests
}

if *enableExternalDNS && !*enableCustomResources {
glog.Fatal("enable-external-dns flag requires -enable-custom-resources")

Check warning on line 392 in cmd/nginx-ingress/flags.go

View check run for this annotation

Codecov / codecov/patch

cmd/nginx-ingress/flags.go#L391-L392

Added lines #L391 - L392 were not covered by tests
}

if *ingressLink != "" && *externalService != "" {
glog.Fatal("ingresslink and external-service cannot both be set")

Check warning on line 396 in cmd/nginx-ingress/flags.go

View check run for this annotation

Codecov / codecov/patch

cmd/nginx-ingress/flags.go#L395-L396

Added lines #L395 - L396 were not covered by tests
}

if *enableDynamicWeightChangesReload && !*nginxPlus {
glog.Warning("weight-changes-dynamic-reload flag support is for NGINX Plus, Dynamic Weight Changes will not be enabled")
*enableDynamicWeightChangesReload = false

Check warning on line 401 in cmd/nginx-ingress/flags.go

View check run for this annotation

Codecov / codecov/patch

cmd/nginx-ingress/flags.go#L399-L401

Added lines #L399 - L401 were not covered by tests
}

if *agent && !*appProtect {
glog.Fatal("NGINX Agent is used to enable the Security Monitoring dashboard and requires NGINX App Protect to be enabled")

Check warning on line 405 in cmd/nginx-ingress/flags.go

View check run for this annotation

Codecov / codecov/patch

cmd/nginx-ingress/flags.go#L404-L405

Added lines #L404 - L405 were not covered by tests
}
}

// validateNamespaceNames validates the namespaces are in the correct format
Expand Down
1 change: 1 addition & 0 deletions cmd/nginx-ingress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
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()

Check warning on line 67 in cmd/nginx-ingress/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/nginx-ingress/main.go#L67

Added line #L67 was not covered by tests
parsedFlags := os.Args[1:]

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