15
15
import os
16
16
import sys
17
17
import time
18
-
19
18
from importlib .machinery import PathFinder
20
19
21
20
# Define some debug logging routines to help sort out things when this
@@ -108,12 +107,14 @@ def del_sys_path_entry(path):
108
107
python_prefix_matches = expected_python_prefix == actual_python_prefix
109
108
python_version_matches = expected_python_version == actual_python_version
110
109
k8s_operator_enabled = os .environ .get ("NEW_RELIC_K8S_OPERATOR_ENABLED" , "off" ).lower () in ("on" , "true" , "1" )
110
+ azure_operator_enabled = os .environ .get ("NEW_RELIC_AZURE_OPERATOR_ENABLED" , "off" ).lower () in ("on" , "true" , "1" )
111
111
112
112
log_message ("python_prefix_matches = %r" , python_prefix_matches )
113
113
log_message ("python_version_matches = %r" , python_version_matches )
114
114
log_message ("k8s_operator_enabled = %r" , k8s_operator_enabled )
115
+ log_message ("azure_operator_enabled = %r" , azure_operator_enabled )
115
116
116
- if k8s_operator_enabled or (python_prefix_matches and python_version_matches ):
117
+ if k8s_operator_enabled or azure_operator_enabled or (python_prefix_matches and python_version_matches ):
117
118
# We also need to skip agent initialisation if neither the license
118
119
# key or config file environment variables are set. We do this as
119
120
# some people like to use a common startup script which always uses
@@ -129,24 +130,10 @@ def del_sys_path_entry(path):
129
130
log_message ("initialize_agent = %r" , initialize_agent )
130
131
131
132
if initialize_agent :
132
- if not k8s_operator_enabled :
133
- # When installed as an egg with buildout, the root directory for
134
- # packages is not listed in sys.path and scripts instead set it
135
- # after Python has started up. This will cause importing of
136
- # 'newrelic' module to fail. What we do is see if the root
137
- # directory where the package is held is in sys.path and if not
138
- # insert it. For good measure we remove it after having imported
139
- # 'newrelic' module to reduce chance that will cause any issues.
140
- # If it is a buildout created script, it will replace the whole
141
- # sys.path again later anyway.
142
- root_directory = os .path .dirname (os .path .dirname (boot_directory ))
143
- log_message ("root_directory = %r" , root_directory )
144
-
145
- new_relic_path = root_directory
146
- do_insert_path = root_directory not in sys .path
147
- else :
148
- # When installed with the kubernetes operator, we need to attempt
149
- # to find a distribution from our initcontainer that matches the
133
+ if k8s_operator_enabled or azure_operator_enabled :
134
+ # When installed with either the kubernetes operator or the
135
+ # azure operator functionality enabled, we need to attempt to
136
+ # find a distribution from our initcontainer that matches the
150
137
# current environment. For wheels, this is platform dependent and we
151
138
# rely on pip to identify the correct wheel to use. If no suitable
152
139
# wheel can be found, we will fall back to the sdist and disable
@@ -155,12 +142,29 @@ def del_sys_path_entry(path):
155
142
# the 'newrelic' module later and use our APIs in their code.
156
143
try :
157
144
sys .path .insert (0 , boot_directory )
145
+ # Will use the same file for k8s as well as Azure since the functionality
146
+ # will remain the same. File may be renamed in the near future.
158
147
from newrelic_k8s_operator import find_supported_newrelic_distribution
159
148
finally :
160
149
del_sys_path_entry (boot_directory )
161
150
162
151
new_relic_path = find_supported_newrelic_distribution ()
163
152
do_insert_path = True
153
+ else :
154
+ # When installed as an egg with buildout, the root directory for
155
+ # packages is not listed in sys.path and scripts instead set it
156
+ # after Python has started up. This will cause importing of
157
+ # 'newrelic' module to fail. What we do is see if the root
158
+ # directory where the package is held is in sys.path and if not
159
+ # insert it. For good measure we remove it after having imported
160
+ # 'newrelic' module to reduce chance that will cause any issues.
161
+ # If it is a buildout created script, it will replace the whole
162
+ # sys.path again later anyway.
163
+ root_directory = os .path .dirname (os .path .dirname (boot_directory ))
164
+ log_message ("root_directory = %r" , root_directory )
165
+
166
+ new_relic_path = root_directory
167
+ do_insert_path = root_directory not in sys .path
164
168
165
169
# Now that the appropriate location of the module has been identified,
166
170
# either by the kubernetes operator or this script, we are ready to import
0 commit comments