@@ -3476,13 +3476,18 @@ def __get_log_config_for_container(self, cid, info, k8s_cache, base_attributes):
34763476 # Based on the pod annotations in a format {container_name}.{team}.secret={secret_name}
34773477 # we might want to add api_keys parameter
34783478
3479- if container_annotations or all_annotations or namespace_annotations :
3479+ self ._logger .log (
3480+ scalyr_logging .DEBUG_LEVEL_0 ,
3481+ "log_config_for_container Checking for teams in annotations for container %s(%s), pod %s, namespace %s. Container annotations = %s, Pod annotations = %s, Namespace annotations = %s " \
3482+ % (info ["name" ], short_cid , pod_name , pod_namespace , container_annotations , all_annotations , namespace_annotations )
3483+ )
34803484
3481- api_keys = self .__container_api_keys_from_annotations (k8s_cache , pod_namespace , container_annotations )
3485+ if container_annotations or all_annotations or namespace_annotations :
3486+ api_keys = self .__container_api_keys_from_annotations (k8s_cache , pod_namespace , container_annotations , "container" , info ["name" ])
34823487 if not api_keys :
3483- api_keys = self .__container_api_keys_from_annotations (k8s_cache , pod_namespace , all_annotations )
3488+ api_keys = self .__container_api_keys_from_annotations (k8s_cache , pod_namespace , all_annotations , "pod" , info [ "name" ] )
34843489 if not api_keys :
3485- api_keys = self .__container_api_keys_from_annotations (k8s_cache , pod_namespace , namespace_annotations )
3490+ api_keys = self .__container_api_keys_from_annotations (k8s_cache , pod_namespace , namespace_annotations , "namespace" , info [ "name" ] )
34863491 if api_keys :
34873492 # Multiple matching api keys will result in multiple log configs, which will differ in the api_key field only.
34883493 results = [
@@ -3492,7 +3497,7 @@ def __get_log_config_for_container(self, cid, info, k8s_cache, base_attributes):
34923497
34933498 return results
34943499
3495- def __container_api_keys_from_annotations (self , k8s_cache , namespace , annotations ):
3500+ def __container_api_keys_from_annotations (self , k8s_cache , namespace , annotations , annotation_kind , container_name ):
34963501 def fetch_secret (name ):
34973502 if not name :
34983503 return None
@@ -3530,17 +3535,31 @@ def get_secret_api_key(secret):
35303535
35313536 return api_key
35323537
3533- api_keys = [
3534- get_secret_api_key ( fetch_secret ( team .get ("secret" )) )
3538+ secrets_names = [
3539+ team .get ("secret" )
35353540 for team in annotations .get ("teams" , [])
35363541 ]
35373542
3538- return [
3543+ secrets = [
3544+ secret
3545+ for secret in map (fetch_secret , secrets_names )
3546+ if secret
3547+ ]
3548+
3549+ api_keys = [
35393550 api_key
3540- for api_key in api_keys
3551+ for api_key in map ( get_secret_api_key , secrets )
35413552 if api_key
35423553 ]
35433554
3555+ self ._logger .log (
3556+ scalyr_logging .DEBUG_LEVEL_0 ,
3557+ "log_config_for_container From %s annotations of container %s and namespace %s, got %d non-empty api keys, %d secrets for secret names %s" \
3558+ % (annotation_kind , container_name , namespace , len (api_keys ), len (secrets ), "," .join (secrets_names ))
3559+ )
3560+
3561+ return api_keys
3562+
35443563 def __get_docker_logs (self , containers , k8s_cache ):
35453564 # type: (Dict, KubernetesCache) -> List[DockerLog]
35463565 """Returns a list of dicts containing the container id, stream, and a log_config
0 commit comments