@@ -191,7 +191,6 @@ static int fetch_pod_service_map(struct flb_kube *ctx, char *api_server_url) {
191
191
struct flb_http_client * c ;
192
192
size_t b_sent ;
193
193
struct flb_upstream_conn * u_conn ;
194
- struct flb_upstream * u ;
195
194
char * buffer = {0 };
196
195
197
196
flb_plg_debug (ctx -> ins , "fetch pod to service map" );
@@ -203,15 +202,25 @@ static int fetch_pod_service_map(struct flb_kube *ctx, char *api_server_url) {
203
202
}
204
203
else {
205
204
/* Get upstream context and connection */
206
- u = flb_upstream_create (ctx -> config ,
207
- ctx -> pod_association_host ,
208
- ctx -> pod_association_port ,
209
- FLB_IO_TCP , NULL );
210
- u_conn = flb_upstream_conn_get (u );
205
+ /* if block handles the TLS certificates update, as the Fluent-bit connection gets net timeout error, it destroys the upstream
206
+ * On the next call to fetch_pod_service_map, it creates a new pod association upstream with latest TLS certs */
207
+ if (!ctx -> pod_association_upstream ) {
208
+ flb_plg_debug (ctx -> ins , "[kubernetes] upstream object for pod association is NULL. Making a new one now" );
209
+ ret = flb_kube_pod_association_init (ctx ,ctx -> config );
210
+ if ( ret == -1 ) {
211
+ return -1 ;
212
+ }
213
+ }
214
+
215
+ u_conn = flb_upstream_conn_get (ctx -> pod_association_upstream );
211
216
if (!u_conn ) {
212
- flb_plg_error (ctx -> ins , "no upstream connections available to %s:%i" ,
213
- u -> tcp_host , u -> tcp_port );
214
- return FLB_RETRY ;
217
+ flb_plg_error (ctx -> ins , "[kubernetes] no upstream connections available to %s:%i" ,
218
+ ctx -> pod_association_upstream -> tcp_host , ctx -> pod_association_upstream -> tcp_port );
219
+ flb_upstream_destroy (ctx -> pod_association_upstream );
220
+ flb_tls_destroy (ctx -> pod_association_tls );
221
+ ctx -> pod_association_upstream = NULL ;
222
+ ctx -> pod_association_tls = NULL ;
223
+ return -1 ;
215
224
}
216
225
217
226
/* Create HTTP client */
@@ -221,7 +230,12 @@ static int fetch_pod_service_map(struct flb_kube *ctx, char *api_server_url) {
221
230
ctx -> pod_association_port , NULL , 0 );
222
231
223
232
if (!c ) {
224
- flb_error ("[kube_meta] could not create HTTP client" );
233
+ flb_error ("[kubernetes] could not create HTTP client" );
234
+ flb_upstream_conn_release (u_conn );
235
+ flb_upstream_destroy (ctx -> pod_association_upstream );
236
+ flb_tls_destroy (ctx -> pod_association_tls );
237
+ ctx -> pod_association_upstream = NULL ;
238
+ ctx -> pod_association_tls = NULL ;
225
239
return -1 ;
226
240
}
227
241
@@ -1159,7 +1173,7 @@ static struct flb_config_map config_map[] = {
1159
1173
* Will only check when "use_pod_association" config is set to true
1160
1174
*/
1161
1175
{
1162
- FLB_CONFIG_MAP_STR , "pod_association_host" , "127.0.0.1 " ,
1176
+ FLB_CONFIG_MAP_STR , "pod_association_host" , "cloudwatch-agent.amazon-cloudwatch " ,
1163
1177
0 , FLB_TRUE , offsetof(struct flb_kube , pod_association_host ),
1164
1178
"host to connect with when performing pod to service name association"
1165
1179
},
@@ -1202,7 +1216,32 @@ static struct flb_config_map config_map[] = {
1202
1216
0 , FLB_TRUE , offsetof(struct flb_kube , pod_service_preload_cache_dir ),
1203
1217
"set directory with pod to service map files"
1204
1218
},
1205
-
1219
+ {
1220
+ FLB_CONFIG_MAP_STR , "pod_association_host_server_ca_file" , "/etc/amazon-cloudwatch-observability-agent-server-cert/tls-ca.crt" ,
1221
+ 0 , FLB_TRUE , offsetof(struct flb_kube , pod_association_host_server_ca_file ),
1222
+ "TLS CA certificate path for communication with agent server"
1223
+ },
1224
+ {
1225
+ FLB_CONFIG_MAP_STR , "pod_association_host_client_cert_file" , "/etc/amazon-cloudwatch-observability-agent-client-cert/client.crt" ,
1226
+ 0 , FLB_TRUE , offsetof(struct flb_kube , pod_association_host_client_cert_file ),
1227
+ "Client Certificate path for enabling mTLS on calls to agent server"
1228
+ },
1229
+ {
1230
+ FLB_CONFIG_MAP_STR , "pod_association_host_client_key_file" , "/etc/amazon-cloudwatch-observability-agent-client-cert/client.key" ,
1231
+ 0 , FLB_TRUE , offsetof(struct flb_kube , pod_association_host_client_key_file ),
1232
+ "Client Certificate Key path for enabling mTLS on calls to agent server"
1233
+ },
1234
+ {
1235
+ FLB_CONFIG_MAP_INT , "pod_association_host_tls_debug" , "0" ,
1236
+ 0 , FLB_TRUE , offsetof(struct flb_kube , pod_association_host_tls_debug ),
1237
+ "set TLS debug level: 0 (no debug), 1 (error), "
1238
+ "2 (state change), 3 (info) and 4 (verbose)"
1239
+ },
1240
+ {
1241
+ FLB_CONFIG_MAP_BOOL , "pod_association_host_tls_verify" , "true" ,
1242
+ 0 , FLB_TRUE , offsetof(struct flb_kube , pod_association_host_tls_verify ),
1243
+ "enable or disable verification of TLS peer certificate"
1244
+ },
1206
1245
/* EOF */
1207
1246
{0 }
1208
1247
};
0 commit comments