22
22
CF_URL = os .getenv ('CF_URL' , 'https://g.codefresh.io' )
23
23
CF_API_KEY = os .getenv ('CF_API_KEY' )
24
24
CF_STEP_NAME = os .getenv ('CF_STEP_NAME' , 'STEP_NAME' )
25
- LOG_LEVEL = os .getenv ('LOG_LEVEL' , "info " )
25
+ LOG_LEVEL = os .getenv ('LOG_LEVEL' , "error " )
26
26
27
27
# Check the certificate or not accessing the API endpoint
28
28
VERIFY = True if os .getenv ('INSECURE' , "False" ).lower () == "false" else False
@@ -50,24 +50,24 @@ def main():
50
50
ingress_host = get_runtime_ingress_host ()
51
51
execute_argocd_sync (ingress_host )
52
52
namespace = get_runtime_ns ()
53
- status = get_app_status (namespace )
53
+ status = get_app_status (ingress_host )
54
54
55
55
if WAIT_HEALTHY :
56
- status = waitHealthy (namespace )
56
+ status = waitHealthy (ingress_host )
57
57
58
58
# if Wait failed, it's time for rollback
59
59
if status != "HEALTHY" and ROLLBACK :
60
60
logging .info ("Application '%s' did not sync properly. Initiating rollback " , APPLICATION )
61
61
revision = getRevision (namespace )
62
- logging .info ("latest healthy revision is %d" , revision )
62
+ logging .info ("Latest healthy revision is %d" , revision )
63
63
64
64
rollback (ingress_host , namespace , revision )
65
65
logging .info ("Waiting for rollback to happen" )
66
66
if WAIT_ROLLBACK :
67
- status = waitHealthy (namespace )
67
+ status = waitHealthy (ingress_host )
68
68
else :
69
69
time .sleep (INTERVAL )
70
- status = get_app_status (namespace )
70
+ status = get_app_status (ingress_host )
71
71
else :
72
72
export_variable ('ROLLBACK_EXECUTED' , "false" )
73
73
else :
@@ -108,7 +108,7 @@ def getRevision(namespace):
108
108
}
109
109
}
110
110
result = client .execute (query , variable_values = variables )
111
- logging .info ( result )
111
+ logging .debug ( "getRevision result: %s" , result )
112
112
113
113
loop = 0
114
114
revision = - 1
@@ -124,18 +124,18 @@ def getRevision(namespace):
124
124
loop += 1
125
125
# we did not find a HEALTHY one in our page
126
126
export_variable ('ROLLBACK_EXECUTED' , "false" )
127
- logging .error ("Did not find a HEALTHY release among the lat %d" , PAGE_SIZE )
127
+ logging .error ("Did not find a HEALTHY release among the last %d" , PAGE_SIZE )
128
128
sys .exit (1 )
129
129
130
- def waitHealthy (namespace ):
131
- logging .debug ("Entering waitHealthy (ns: %s)" , namespace )
130
+ def waitHealthy (ingress_host ):
131
+ logging .debug ("Entering waitHealthy (ns: %s)" , ingress_host )
132
132
133
133
time .sleep (INTERVAL )
134
- status = get_app_status (namespace )
134
+ status = get_app_status (ingress_host )
135
135
logging .info ("App status is %s" , status )
136
136
loop = 0
137
137
while status != "HEALTHY" and loop < MAX_CHECKS :
138
- status = get_app_status (namespace )
138
+ status = get_app_status (ingress_host )
139
139
time .sleep (INTERVAL )
140
140
logging .info ("App status is %s after %d checks" , status , loop )
141
141
loop += 1
@@ -160,15 +160,15 @@ def rollback(ingress_host, namespace, revision):
160
160
"dryRun" : False ,
161
161
"prune" : True
162
162
}
163
- logging .info ("Rollback app : %s" , variables )
163
+ logging .debug ("Rollback variables : %s" , variables )
164
164
result = client .execute (query , variable_values = variables )
165
- logging .info ( result )
165
+ logging .debug ( "Rollback result: %s" , result )
166
166
export_variable ('ROLLBACK_EXECUTED' , "true" )
167
167
168
168
169
- def get_app_status (namespace ):
169
+ def get_app_status (ingress_host ):
170
170
## Get the health status of the app
171
- gql_api_endpoint = CF_URL + '/2.0 /api/graphql'
171
+ gql_api_endpoint = ingress_host + '/app-proxy /api/graphql'
172
172
transport = RequestsHTTPTransport (
173
173
url = gql_api_endpoint ,
174
174
headers = {'authorization' : CF_API_KEY },
@@ -178,13 +178,12 @@ def get_app_status(namespace):
178
178
client = Client (transport = transport , fetch_schema_from_transport = False )
179
179
query = get_query ('get_app_status' ) ## gets gql query
180
180
variables = {
181
- "runtime" : RUNTIME ,
182
- "name" : APPLICATION ,
183
- "namespace" : namespace
181
+ "name" : APPLICATION
184
182
}
185
183
result = client .execute (query , variable_values = variables )
186
184
187
- health = result ['application' ]['healthStatus' ]
185
+ logging .debug ("App Status result: %s" , result )
186
+ health = result ['applicationProxyQuery' ]['status' ]['health' ]['status' ]
188
187
return health
189
188
190
189
def get_query (query_name ):
@@ -245,9 +244,8 @@ def execute_argocd_sync(ingress_host):
245
244
"prune" : True
246
245
}
247
246
}
248
- logging .info ("Syncing app: %s" , variables )
249
247
result = client .execute (query , variable_values = variables )
250
- logging .info ( result )
248
+ logging .debug ( "Syncing App result: %s" , result )
251
249
252
250
253
251
def export_variable (var_name , var_value ):
@@ -260,7 +258,7 @@ def export_variable(var_name, var_value):
260
258
with open ('/meta/env_vars_to_export' , 'a' ) as a_writer :
261
259
a_writer .write (var_name + "=" + var_value + '\n ' )
262
260
263
- logging .info ("Exporting variable: %s=%s" , var_name , var_value )
261
+ logging .debug ("Exporting variable: %s=%s" , var_name , var_value )
264
262
265
263
##############################################################
266
264
0 commit comments