@@ -12,20 +12,28 @@ import (
1212const (
1313LatticeGatewayControllerName = "application-networking.k8s.aws/gateway-api-controller"
1414defaultLogLevel = "Info"
15- NoDefaultServiceNetwork = ""
16- NO_DEFAULT_SERVICE_NETWORK = "NO_DEFAULT_SERVICE_NETWORK"
15+ UnknownInput = ""
1716)
1817
19- // TODO endpoint, region
20- var VpcID = "vpc-xxxx"
21- var AccountID = "yyyyyy"
22- var Region = "us-west-2"
18+ const (
19+ NO_DEFAULT_SERVICE_NETWORK = "NO_DEFAULT_SERVICE_NETWORK"
20+ REGION = "REGION"
21+ CLUSTER_VPC_ID = "CLUSTER_VPC_ID"
22+ CLUSTER_LOCAL_GATEWAY = "CLUSTER_LOCAL_GATEWAY"
23+ AWS_ACCOUNT_ID = "AWS_ACCOUNT_ID"
24+ TARGET_GROUP_NAME_LEN_MODE = "TARGET_GROUP_NAME_LEN_MODE"
25+ GATEWAY_API_CONTROLLER_LOGLEVEL = "GATEWAY_API_CONTROLLER_LOGLEVEL"
26+ )
27+
28+ var VpcID = UnknownInput
29+ var AccountID = UnknownInput
30+ var Region = UnknownInput
2331var logLevel = defaultLogLevel
24- var DefaultServiceNetwork = NoDefaultServiceNetwork
32+ var DefaultServiceNetwork = UnknownInput
2533var UseLongTGName = false
2634
2735func GetLogLevel () string {
28- logLevel = os .Getenv (" GATEWAY_API_CONTROLLER_LOGLEVEL" )
36+ logLevel = os .Getenv (GATEWAY_API_CONTROLLER_LOGLEVEL )
2937switch strings .ToLower (logLevel ) {
3038case "debug" :
3139return "10"
@@ -36,86 +44,74 @@ func GetLogLevel() string {
3644}
3745
3846func GetClusterLocalGateway () (string , error ) {
39- if DefaultServiceNetwork == NoDefaultServiceNetwork {
40- return NoDefaultServiceNetwork , errors .New (NO_DEFAULT_SERVICE_NETWORK )
47+ if DefaultServiceNetwork == UnknownInput {
48+ return UnknownInput , errors .New (NO_DEFAULT_SERVICE_NETWORK )
4149}
4250
4351return DefaultServiceNetwork , nil
4452}
4553
4654func ConfigInit () {
47- // discover VPC using environment first
48- VpcID = os .Getenv ("CLUSTER_VPC_ID" )
49- glog .V (2 ).Infoln ("CLUSTER_VPC_ID: " , os .Getenv ("CLUSTER_VPC_ID" ))
50-
51- // discover Account
52- AccountID = os .Getenv ("AWS_ACCOUNT_ID" )
53- if AccountID == "" {
54- AccountID = os .Getenv ("AWS_ACCOUNT" ) // Fallback to AWS_ACCOUNT for compatibility
55- }
56- glog .V (2 ).Infoln ("AWS_ACCOUNT_ID:" , AccountID )
57-
58- // discover Region
59- Region = os .Getenv ("REGION" )
60- glog .V (2 ).Infoln ("REGION:" , os .Getenv ("REGION" ))
61-
62- logLevel = os .Getenv ("GATEWAY_API_CONTROLLER_LOGLEVEL" )
63- glog .V (2 ).Infoln ("Logging Level:" , os .Getenv ("GATEWAY_API_CONTROLLER_LOGLEVEL" ))
64-
65- DefaultServiceNetwork = os .Getenv ("CLUSTER_LOCAL_GATEWAY" )
66-
67- if DefaultServiceNetwork == NoDefaultServiceNetwork {
68- glog .V (2 ).Infoln ("No CLUSTER_LOCAL_GATEWAY" )
69- } else {
70-
71- glog .V (2 ).Infoln ("CLUSTER_LOCAL_GATEWAY" , DefaultServiceNetwork )
72- }
73-
74- tgNameLengthMode := os .Getenv ("TARGET_GROUP_NAME_LEN_MODE" )
75-
76- glog .V (2 ).Infoln ("TARGET_GROUP_NAME_LEN_MODE" , tgNameLengthMode )
77-
78- if tgNameLengthMode == "long" {
79- UseLongTGName = true
80- } else {
81- UseLongTGName = false
82- }
8355
8456sess , _ := session .NewSession ()
8557metadata := NewEC2Metadata (sess )
86-
8758var err error
88- if ifRunningInCluster () {
59+
60+ // CLUSTER_VPC_ID
61+ VpcID = os .Getenv (CLUSTER_VPC_ID )
62+ if VpcID != UnknownInput {
63+ glog .V (2 ).Infoln ("CLUSTER_VPC_ID passed as input:" , VpcID )
64+ } else {
8965VpcID , err = metadata .VpcID ()
66+ glog .V (2 ).Infoln ("CLUSTER_VPC_ID from IMDS config discovery :" , VpcID )
9067if err != nil {
91- return
68+ glog . V ( 2 ). Infoln ( "IMDS config discovery for CLUSTER_VPC_ID is NOT AVAILABLE :" , err )
9269}
70+ }
71+
72+ // REGION
73+ Region = os .Getenv (REGION )
74+ if Region != UnknownInput {
75+ glog .V (2 ).Infoln ("REGION passed as input:" , Region )
76+ } else {
9377Region , err = metadata .Region ()
78+ glog .V (2 ).Infoln ("REGION from IMDS config discovery :" , Region )
9479if err != nil {
95- return
80+ glog . V ( 2 ). Infoln ( "IMDS config discovery for REGION is NOT AVAILABLE :" , err )
9681}
82+ }
83+
84+ // AWS_ACCOUNT_ID
85+ AccountID = os .Getenv (AWS_ACCOUNT_ID )
86+ if AccountID != UnknownInput {
87+ glog .V (2 ).Infoln ("AWS_ACCOUNT_ID passed as input:" , AccountID )
88+ } else {
9789AccountID , err = metadata .AccountId ()
90+ glog .V (2 ).Infoln ("AWS_ACCOUNT_ID from IMDS config discovery :" , AccountID )
9891if err != nil {
99- return
92+ glog . V ( 2 ). Infoln ( "IMDS config discovery for AWS_ACCOUNT_ID is NOT AVAILABLE :" , err )
10093}
101- glog .V (2 ).Infoln ("INSIDE CLUSTER CLUSTER_VPC_ID: " , VpcID )
102- glog .V (2 ).Infoln ("INSIDE CLUSTER REGION: " , Region )
103- glog .V (2 ).Infoln ("INSIDE CLUSTER ACCOUNT_ID: " , AccountID )
10494}
105- }
10695
107- func ifRunningInCluster () bool {
108- _ , err := os .Stat ("/var/run/secrets/kubernetes.io/serviceaccount" )
109- if err == nil {
110- glog .V (2 ).Infoln ("Controller is running inside cluster" )
111- return true
112- }
96+ // GATEWAY_API_CONTROLLER_LOGLEVEL
97+ logLevel = os .Getenv (GATEWAY_API_CONTROLLER_LOGLEVEL )
98+ glog .V (2 ).Infoln ("Logging Level:" , os .Getenv (GATEWAY_API_CONTROLLER_LOGLEVEL ))
11399
114- if os .IsNotExist (err ) {
115- glog .V (2 ).Infoln ("Controller is NOT running inside cluster" )
116- return false
100+ // CLUSTER_LOCAL_GATEWAY
101+ DefaultServiceNetwork = os .Getenv (CLUSTER_LOCAL_GATEWAY )
102+ if DefaultServiceNetwork == UnknownInput {
103+ glog .V (2 ).Infoln ("No CLUSTER_LOCAL_GATEWAY" )
104+ } else {
105+ glog .V (2 ).Infoln ("CLUSTER_LOCAL_GATEWAY" , DefaultServiceNetwork )
117106}
118107
119- glog .V (2 ).Infoln ("Controller is NOT running inside cluster" )
120- return false
108+ // TARGET_GROUP_NAME_LEN_MODE
109+ tgNameLengthMode := os .Getenv (TARGET_GROUP_NAME_LEN_MODE )
110+ glog .V (2 ).Infoln ("TARGET_GROUP_NAME_LEN_MODE" , tgNameLengthMode )
111+
112+ if tgNameLengthMode == "long" {
113+ UseLongTGName = true
114+ } else {
115+ UseLongTGName = false
116+ }
121117}
0 commit comments