@@ -23,6 +23,7 @@ import (
2323 "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static"
2424 "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/config"
2525 "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/licensing"
26+ ngxConfig "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/nginx/config"
2627 "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/nginx/file"
2728)
2829
@@ -161,16 +162,6 @@ func createStaticModeCommand() *cobra.Command {
161162 return fmt .Errorf ("error validating ports: %w" , err )
162163 }
163164
164- podIP := os .Getenv ("POD_IP" )
165- if err := validateIP (podIP ); err != nil {
166- return fmt .Errorf ("error validating POD_IP environment variable: %w" , err )
167- }
168-
169- podNsName , err := getPodNsName ()
170- if err != nil {
171- return fmt .Errorf ("could not get pod namespaced name: %w" , err )
172- }
173-
174165 imageSource := os .Getenv ("BUILD_AGENT" )
175166 if imageSource != "gha" && imageSource != "local" {
176167 imageSource = "unknown"
@@ -215,6 +206,11 @@ func createStaticModeCommand() *cobra.Command {
215206
216207 flagKeys , flagValues := parseFlags (cmd .Flags ())
217208
209+ podConfig , err := createGatewayPodConfig (serviceName .value )
210+ if err != nil {
211+ return fmt .Errorf ("error creating gateway pod config: %w" , err )
212+ }
213+
218214 conf := config.Config {
219215 GatewayCtlrName : gatewayCtlrName .value ,
220216 ConfigName : configName .String (),
@@ -223,12 +219,7 @@ func createStaticModeCommand() *cobra.Command {
223219 GatewayClassName : gatewayClassName .value ,
224220 GatewayNsName : gwNsName ,
225221 UpdateGatewayClassStatus : updateGCStatus ,
226- GatewayPodConfig : config.GatewayPodConfig {
227- PodIP : podIP ,
228- ServiceName : serviceName .value ,
229- Namespace : podNsName .Namespace ,
230- Name : podNsName .Name ,
231- },
222+ GatewayPodConfig : podConfig ,
232223 HealthConfig : config.HealthConfig {
233224 Enabled : ! disableHealth ,
234225 Port : healthListenPort .value ,
@@ -241,7 +232,7 @@ func createStaticModeCommand() *cobra.Command {
241232 LeaderElection : config.LeaderElectionConfig {
242233 Enabled : ! disableLeaderElection ,
243234 LockName : leaderElectionLockName .String (),
244- Identity : podNsName .Name ,
235+ Identity : podConfig .Name ,
245236 },
246237 UsageReportConfig : usageReportConfig ,
247238 ProductTelemetryConfig : config.ProductTelemetryConfig {
@@ -539,9 +530,9 @@ func createInitializeCommand() *cobra.Command {
539530 return err
540531 }
541532
542- podNsName , err := getPodNsName ( )
533+ podUID , err := getValueFromEnv ( "POD_UID" )
543534 if err != nil {
544- return fmt .Errorf ("could not get pod namespaced name : %w" , err )
535+ return fmt .Errorf ("could not get pod UID : %w" , err )
545536 }
546537
547538 clusterCfg := ctlr .GetConfigOrDie ()
@@ -563,15 +554,16 @@ func createInitializeCommand() *cobra.Command {
563554
564555 dcc := licensing .NewDeploymentContextCollector (licensing.DeploymentContextCollectorConfig {
565556 K8sClientReader : k8sReader ,
566- PodNSName : podNsName ,
557+ PodUID : podUID ,
567558 Logger : logger .WithName ("deployCtxCollector" ),
568559 })
569560
570561 return initialize (initializeConfig {
571- fileManager : file .NewStdLibOSFileManager (),
572- logger : logger ,
573- plus : plus ,
574- collector : dcc ,
562+ fileManager : file .NewStdLibOSFileManager (),
563+ fileGenerator : ngxConfig .NewGeneratorImpl (plus , nil , logger .WithName ("generator" )),
564+ logger : logger ,
565+ plus : plus ,
566+ collector : dcc ,
575567 copy : copyFiles {
576568 srcFileNames : srcFiles ,
577569 destDirName : dest ,
@@ -652,16 +644,43 @@ func getBuildInfo() (commitHash string, commitTime string, dirtyBuild string) {
652644 return
653645}
654646
655- func getPodNsName ( ) (types. NamespacedName , error ) {
656- namespace := os . Getenv ( "POD_NAMESPACE " )
657- if namespace == "" {
658- return types. NamespacedName {}, errors . New ( "POD_NAMESPACE environment variable must be set" )
647+ func createGatewayPodConfig ( svcName string ) (config. GatewayPodConfig , error ) {
648+ podIP , err := getValueFromEnv ( "POD_IP " )
649+ if err != nil {
650+ return config. GatewayPodConfig {}, err
659651 }
660652
661- podName := os .Getenv ("POD_NAME" )
662- if podName == "" {
663- return types.NamespacedName {}, errors .New ("POD_NAME environment variable must be set" )
653+ podUID , err := getValueFromEnv ("POD_UID" )
654+ if err != nil {
655+ return config.GatewayPodConfig {}, err
656+ }
657+
658+ ns , err := getValueFromEnv ("POD_NAMESPACE" )
659+ if err != nil {
660+ return config.GatewayPodConfig {}, err
661+ }
662+
663+ name , err := getValueFromEnv ("POD_NAME" )
664+ if err != nil {
665+ return config.GatewayPodConfig {}, err
666+ }
667+
668+ c := config.GatewayPodConfig {
669+ PodIP : podIP ,
670+ ServiceName : svcName ,
671+ Namespace : ns ,
672+ Name : name ,
673+ UID : podUID ,
674+ }
675+
676+ return c , nil
677+ }
678+
679+ func getValueFromEnv (key string ) (string , error ) {
680+ val := os .Getenv (key )
681+ if val == "" {
682+ return "" , fmt .Errorf ("environment variable %s not set" , key )
664683 }
665684
666- return types. NamespacedName { Namespace : namespace , Name : podName } , nil
685+ return val , nil
667686}
0 commit comments