@@ -23,6 +23,7 @@ import (
23
23
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static"
24
24
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/config"
25
25
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/licensing"
26
+ ngxConfig "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/nginx/config"
26
27
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/nginx/file"
27
28
)
28
29
@@ -161,16 +162,6 @@ func createStaticModeCommand() *cobra.Command {
161
162
return fmt .Errorf ("error validating ports: %w" , err )
162
163
}
163
164
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
-
174
165
imageSource := os .Getenv ("BUILD_AGENT" )
175
166
if imageSource != "gha" && imageSource != "local" {
176
167
imageSource = "unknown"
@@ -215,6 +206,11 @@ func createStaticModeCommand() *cobra.Command {
215
206
216
207
flagKeys , flagValues := parseFlags (cmd .Flags ())
217
208
209
+ podConfig , err := createGatewayPodConfig (serviceName .value )
210
+ if err != nil {
211
+ return fmt .Errorf ("error creating gateway pod config: %w" , err )
212
+ }
213
+
218
214
conf := config.Config {
219
215
GatewayCtlrName : gatewayCtlrName .value ,
220
216
ConfigName : configName .String (),
@@ -223,12 +219,7 @@ func createStaticModeCommand() *cobra.Command {
223
219
GatewayClassName : gatewayClassName .value ,
224
220
GatewayNsName : gwNsName ,
225
221
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 ,
232
223
HealthConfig : config.HealthConfig {
233
224
Enabled : ! disableHealth ,
234
225
Port : healthListenPort .value ,
@@ -241,7 +232,7 @@ func createStaticModeCommand() *cobra.Command {
241
232
LeaderElection : config.LeaderElectionConfig {
242
233
Enabled : ! disableLeaderElection ,
243
234
LockName : leaderElectionLockName .String (),
244
- Identity : podNsName .Name ,
235
+ Identity : podConfig .Name ,
245
236
},
246
237
UsageReportConfig : usageReportConfig ,
247
238
ProductTelemetryConfig : config.ProductTelemetryConfig {
@@ -539,9 +530,9 @@ func createInitializeCommand() *cobra.Command {
539
530
return err
540
531
}
541
532
542
- podNsName , err := getPodNsName ( )
533
+ podUID , err := getValueFromEnv ( "POD_UID" )
543
534
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 )
545
536
}
546
537
547
538
clusterCfg := ctlr .GetConfigOrDie ()
@@ -563,15 +554,16 @@ func createInitializeCommand() *cobra.Command {
563
554
564
555
dcc := licensing .NewDeploymentContextCollector (licensing.DeploymentContextCollectorConfig {
565
556
K8sClientReader : k8sReader ,
566
- PodNSName : podNsName ,
557
+ PodUID : podUID ,
567
558
Logger : logger .WithName ("deployCtxCollector" ),
568
559
})
569
560
570
561
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 ,
575
567
copy : copyFiles {
576
568
srcFileNames : srcFiles ,
577
569
destDirName : dest ,
@@ -652,16 +644,43 @@ func getBuildInfo() (commitHash string, commitTime string, dirtyBuild string) {
652
644
return
653
645
}
654
646
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
659
651
}
660
652
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 )
664
683
}
665
684
666
- return types. NamespacedName { Namespace : namespace , Name : podName } , nil
685
+ return val , nil
667
686
}
0 commit comments