Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cmd/nginx-ingress/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ var (
`Path to the TransportServer NGINX configuration template for a TransportServer resource.
(default for NGINX "nginx.transportserver.tmpl"; default for NGINX Plus "nginx-plus.transportserver.tmpl")`)

oidcTemplatePath = flag.String("oidc-template-path", "",
`Path to the OIDC NGINX configuration template.
(default for NGINX Plus "oidc.tmpl")`)

externalService = flag.String("external-service", "",
`Specifies the name of the service with the type LoadBalancer through which the Ingress Controller pods are exposed externally.
The external address of the service is used when reporting the status of Ingress, VirtualServer and VirtualServerRoute resources. For Ingress resources only: Requires -report-ingress-status.`)
Expand Down Expand Up @@ -429,7 +433,7 @@ func mustValidateFlags(ctx context.Context) {
nl.Fatal(l, "ingresslink and external-service cannot both be set")
}

if *nginxPlus && *mgmtConfigMap == "" {
if *nginxPlus && *mgmtConfigMap == "" && *proxyURL == "" {
nl.Fatal(l, "NGINX Plus requires a mgmt ConfigMap to be set")
}
}
Expand Down
78 changes: 60 additions & 18 deletions cmd/nginx-ingress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ func main() {
ctx := initLogger(*logFormat, logLevels[*logLevel], os.Stdout)
l := nl.LoggerFromContext(ctx)

cleanupSocketFiles(l)
// TODO: Use fake manager
if *proxyURL == "" {
cleanupSocketFiles(l)
}

initValidate(ctx)
parsedFlags := os.Args[1:]
Expand All @@ -103,10 +106,36 @@ func main() {
if err := validateKubernetesVersionInfo(ctx, kubeClient); err != nil {
nl.Fatal(l, err)
}
pod, err := kubeClient.CoreV1().Pods(controllerNamespace).Get(context.TODO(), podName, meta_v1.GetOptions{})
if err != nil {
nl.Fatalf(l, "Failed to get pod: %v", err)

var pod *api_v1.Pod

if *proxyURL != "" {
if controllerNamespace == "" {
controllerNamespace = "nginx-ingress"
}
if podName == "" {
podName = "nginx-ingress-controller-proxy-mode"
}
pod = &api_v1.Pod{
ObjectMeta: meta_v1.ObjectMeta{
Name: podName,
Namespace: controllerNamespace,
OwnerReferences: []meta_v1.OwnerReference{
{
Kind: "Deployment",
Name: "nginx-ingress-controller-proxy-mode",
},
},
},
}
} else {
var err error
pod, err = kubeClient.CoreV1().Pods(controllerNamespace).Get(context.TODO(), podName, meta_v1.GetOptions{})
if err != nil {
nl.Fatalf(l, "Failed to get pod: %v", err)
}
}

eventBroadcaster := record.NewBroadcaster()
eventBroadcaster.StartLogging(func(format string, args ...interface{}) {
nl.Infof(l, format, args...)
Expand All @@ -129,13 +158,13 @@ func main() {

var licenseReporter *license_reporting.LicenseReporter

if *nginxPlus {
if *nginxPlus && *proxyURL == "" {
licenseReporter = license_reporting.NewLicenseReporter(kubeClient, eventRecorder, pod)
}

var deploymentMetadata *metadata.Metadata

if *agent {
if *agent && *proxyURL == "" {
deploymentMetadata = metadata.NewMetadataReporter(kubeClient, pod, version)
}

Expand All @@ -156,15 +185,28 @@ func main() {
}

var agentVersion string
if *agent {
if *agent && *proxyURL == "" {
agentVersion = getAgentVersionInfo(nginxManager)
}

go updateSelfWithVersionInfo(ctx, eventRecorder, kubeClient, version, appProtectVersion, agentVersion, nginxVersion, 10, time.Second*5)
// Skip pod label updates in proxy mode since the pod may not exist or be accessible
if *proxyURL == "" {
go updateSelfWithVersionInfo(ctx, eventRecorder, kubeClient, version, appProtectVersion, agentVersion, nginxVersion, 10, time.Second*5)
}

var mgmtCfgParams *configs.MGMTConfigParams
if *nginxPlus {
mgmtCfgParams = processMGMTConfigMap(kubeClient, configs.NewDefaultMGMTConfigParams(ctx), eventRecorder, pod)
if *proxyURL == "" {
mgmtCfgParams = processMGMTConfigMap(kubeClient, configs.NewDefaultMGMTConfigParams(ctx), eventRecorder, pod)
} else {
// In proxy mode, also process the mgmt configmap if specified
if *mgmtConfigMap != "" {
mgmtCfgParams = processMGMTConfigMap(kubeClient, configs.NewDefaultMGMTConfigParams(ctx), eventRecorder, pod)
} else {
mgmtCfgParams = configs.NewDefaultMGMTConfigParams(ctx)
}
}

if err := processLicenseSecret(kubeClient, nginxManager, mgmtCfgParams, controllerNamespace); err != nil {
logEventAndExit(ctx, eventRecorder, pod, secretErrorReason, err)
}
Expand All @@ -176,7 +218,6 @@ func main() {
if err := processClientAuthSecret(kubeClient, nginxManager, mgmtCfgParams, controllerNamespace); err != nil {
logEventAndExit(ctx, eventRecorder, pod, secretErrorReason, err)
}

}

templateExecutor, templateExecutorV2 := createTemplateExecutors(ctx)
Expand Down Expand Up @@ -236,12 +277,10 @@ func main() {
DefaultCABundle: caBundlePath,
}

if *nginxPlus {
if cfgParams.ZoneSync.Enable && cfgParams.ZoneSync.Port != 0 {
err := createAndValidateHeadlessService(ctx, kubeClient, cfgParams, controllerNamespace, pod)
if err != nil {
logEventAndExit(ctx, eventRecorder, pod, nl.EventReasonServiceFailedToCreate, err)
}
if *nginxPlus && cfgParams.ZoneSync.Enable && cfgParams.ZoneSync.Port != 0 {
err := createAndValidateHeadlessService(ctx, kubeClient, cfgParams, controllerNamespace, pod)
if err != nil {
logEventAndExit(ctx, eventRecorder, pod, nl.EventReasonServiceFailedToCreate, err)
}
}

Expand All @@ -255,7 +294,7 @@ func main() {
process := startChildProcesses(nginxManager, appProtectV5)

plusClient := createPlusClient(ctx, *nginxPlus, useFakeNginxManager, nginxManager)
if *nginxPlus {
if *nginxPlus && *proxyURL == "" {
licenseReporter.Config.PlusClient = plusClient
}

Expand Down Expand Up @@ -570,6 +609,9 @@ func createTemplateExecutors(ctx context.Context) (*version1.TemplateExecutor, *
if *transportServerTemplatePath != "" {
nginxTransportServerTemplatePath = *transportServerTemplatePath
}
if *oidcTemplatePath != "" {
nginxOIDCConfTemplatePath = *oidcTemplatePath
}

templateExecutor, err := version1.NewTemplateExecutor(nginxConfTemplatePath, nginxIngressTemplatePath)
if err != nil {
Expand All @@ -588,7 +630,7 @@ func createNginxManager(ctx context.Context, managerCollector collectors.Manager
useFakeNginxManager := *proxyURL != ""
var nginxManager nginx.Manager
if useFakeNginxManager {
nginxManager = nginx.NewFakeManager("/etc/nginx")
nginxManager = nginx.NewFakeManager(ctx, "/etc/nginx")
} else {
timeout := time.Duration(*nginxReloadTimeout) * time.Millisecond
nginxManager = nginx.NewLocalManager(ctx, "/etc/nginx/", *nginxDebug, managerCollector, licenseReporter, deploymentMetadata, timeout, *nginxPlus)
Expand Down
2 changes: 1 addition & 1 deletion internal/configs/configurator_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func createTestConfiguratorBench() (*Configurator, error) {
return nil, err
}

manager := nginx.NewFakeManager("/etc/nginx")
manager := nginx.NewFakeManager(context.Background(), "/etc/nginx")
cnf := NewConfigurator(ConfiguratorParams{
NginxManager: manager,
StaticCfgParams: createTestStaticConfigParams(),
Expand Down
4 changes: 2 additions & 2 deletions internal/configs/configurator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func createTestConfigurator(t *testing.T) *Configurator {
t.Fatal(err)
}

manager := nginx.NewFakeManager("/etc/nginx")
manager := nginx.NewFakeManager(context.Background(), "/etc/nginx")
cnf := NewConfigurator(ConfiguratorParams{
NginxManager: manager,
StaticCfgParams: createTestStaticConfigParams(),
Expand Down Expand Up @@ -79,7 +79,7 @@ func createTestConfiguratorInvalidIngressTemplate(t *testing.T) *Configurator {
t.Fatal(err)
}

manager := nginx.NewFakeManager("/etc/nginx")
manager := nginx.NewFakeManager(context.Background(), "/etc/nginx")
cnf := NewConfigurator(ConfiguratorParams{
NginxManager: manager,
StaticCfgParams: createTestStaticConfigParams(),
Expand Down
3 changes: 2 additions & 1 deletion internal/configs/version1/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package version1

import (
"bytes"
"context"
"os"
"strconv"
"strings"
Expand All @@ -13,7 +14,7 @@ import (
"github.com/nginx/kubernetes-ingress/internal/nginx"
)

var fakeManager = nginx.NewFakeManager("/etc/nginx")
var fakeManager = nginx.NewFakeManager(context.Background(), "/etc/nginx")

func TestMain(m *testing.M) {
v := m.Run()
Expand Down
8 changes: 4 additions & 4 deletions internal/nginx/fake_manager.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package nginx

import (
"context"
"log/slog"
"net/http"
"os"
"path"

nl "github.com/nginx/kubernetes-ingress/internal/logger"
nic_glog "github.com/nginx/kubernetes-ingress/internal/logger/glog"
"github.com/nginx/kubernetes-ingress/internal/logger/levels"
"github.com/nginx/nginx-plus-go-client/v3/client"
)

Expand All @@ -21,12 +20,13 @@ type FakeManager struct {
}

// NewFakeManager creates a FakeManager.
func NewFakeManager(confPath string) *FakeManager {
func NewFakeManager(ctx context.Context, confPath string) *FakeManager {
l := nl.LoggerFromContext(ctx)
return &FakeManager{
confdPath: path.Join(confPath, "conf.d"),
secretsPath: path.Join(confPath, "secrets"),
dhparamFilename: path.Join(confPath, "secrets", "dhparam.pem"),
logger: slog.New(nic_glog.New(os.Stdout, &nic_glog.Options{Level: levels.LevelInfo})),
logger: l,
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/telemetry/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2651,7 +2651,7 @@ func newConfigurator(t *testing.T) *configs.Configurator {
t.Fatal(err)
}

manager := nginx.NewFakeManager("/etc/nginx")
manager := nginx.NewFakeManager(context.Background(), "/etc/nginx")
cnf := configs.NewConfigurator(configs.ConfiguratorParams{
NginxManager: manager,
StaticCfgParams: &configs.StaticConfigParams{
Expand Down
Loading