Skip to content

Commit c791f9c

Browse files
authored
Change API call for app status (#673)
* [1.4.2] change API call to improve performance and decrease lag * change some info message into debug * Change logging default level to error to match step * Update default version for image
1 parent 9addaf7 commit c791f9c

File tree

5 files changed

+57
-38
lines changed

5 files changed

+57
-38
lines changed

incubating/argo-cd-sync/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## [1.4.2] - 2024-01-17
4+
### Changed
5+
New graphql call to speed up query
6+
37
## [1.4.1] - 2023-10-31
48
### Changed
59
Add CA_BUNDLE option

incubating/argo-cd-sync/argocd_sync.py

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
CF_URL = os.getenv('CF_URL', 'https://g.codefresh.io')
2323
CF_API_KEY = os.getenv('CF_API_KEY')
2424
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")
2626

2727
# Check the certificate or not accessing the API endpoint
2828
VERIFY = True if os.getenv('INSECURE', "False").lower() == "false" else False
@@ -50,24 +50,24 @@ def main():
5050
ingress_host = get_runtime_ingress_host()
5151
execute_argocd_sync(ingress_host)
5252
namespace=get_runtime_ns()
53-
status = get_app_status(namespace)
53+
status = get_app_status(ingress_host)
5454

5555
if WAIT_HEALTHY:
56-
status=waitHealthy (namespace)
56+
status=waitHealthy (ingress_host)
5757

5858
# if Wait failed, it's time for rollback
5959
if status != "HEALTHY" and ROLLBACK:
6060
logging.info("Application '%s' did not sync properly. Initiating rollback ", APPLICATION)
6161
revision = getRevision(namespace)
62-
logging.info("latest healthy revision is %d", revision)
62+
logging.info("Latest healthy revision is %d", revision)
6363

6464
rollback(ingress_host, namespace, revision)
6565
logging.info("Waiting for rollback to happen")
6666
if WAIT_ROLLBACK:
67-
status=waitHealthy (namespace)
67+
status=waitHealthy (ingress_host)
6868
else:
6969
time.sleep(INTERVAL)
70-
status=get_app_status(namespace)
70+
status=get_app_status(ingress_host)
7171
else:
7272
export_variable('ROLLBACK_EXECUTED', "false")
7373
else:
@@ -108,7 +108,7 @@ def getRevision(namespace):
108108
}
109109
}
110110
result = client.execute(query, variable_values=variables)
111-
logging.info(result)
111+
logging.debug("getRevision result: %s", result)
112112

113113
loop=0
114114
revision = -1
@@ -124,18 +124,18 @@ def getRevision(namespace):
124124
loop += 1
125125
# we did not find a HEALTHY one in our page
126126
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)
128128
sys.exit(1)
129129

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)
132132

133133
time.sleep(INTERVAL)
134-
status = get_app_status(namespace)
134+
status = get_app_status(ingress_host)
135135
logging.info("App status is %s", status)
136136
loop=0
137137
while status != "HEALTHY" and loop < MAX_CHECKS:
138-
status=get_app_status(namespace)
138+
status=get_app_status(ingress_host)
139139
time.sleep(INTERVAL)
140140
logging.info("App status is %s after %d checks", status, loop)
141141
loop += 1
@@ -160,15 +160,15 @@ def rollback(ingress_host, namespace, revision):
160160
"dryRun": False,
161161
"prune": True
162162
}
163-
logging.info("Rollback app: %s", variables)
163+
logging.debug("Rollback variables: %s", variables)
164164
result = client.execute(query, variable_values=variables)
165-
logging.info(result)
165+
logging.debug("Rollback result: %s", result)
166166
export_variable('ROLLBACK_EXECUTED', "true")
167167

168168

169-
def get_app_status(namespace):
169+
def get_app_status(ingress_host):
170170
## 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'
172172
transport = RequestsHTTPTransport(
173173
url=gql_api_endpoint,
174174
headers={'authorization': CF_API_KEY},
@@ -178,13 +178,12 @@ def get_app_status(namespace):
178178
client = Client(transport=transport, fetch_schema_from_transport=False)
179179
query = get_query('get_app_status') ## gets gql query
180180
variables = {
181-
"runtime": RUNTIME,
182-
"name": APPLICATION,
183-
"namespace": namespace
181+
"name": APPLICATION
184182
}
185183
result = client.execute(query, variable_values=variables)
186184

187-
health = result['application']['healthStatus']
185+
logging.debug("App Status result: %s", result)
186+
health = result['applicationProxyQuery']['status']['health']['status']
188187
return health
189188

190189
def get_query(query_name):
@@ -245,9 +244,8 @@ def execute_argocd_sync(ingress_host):
245244
"prune": True
246245
}
247246
}
248-
logging.info("Syncing app: %s", variables)
249247
result = client.execute(query, variable_values=variables)
250-
logging.info(result)
248+
logging.debug("Syncing App result: %s", result)
251249

252250

253251
def export_variable(var_name, var_value):
@@ -260,7 +258,7 @@ def export_variable(var_name, var_value):
260258
with open('/meta/env_vars_to_export', 'a') as a_writer:
261259
a_writer.write(var_name + "=" + var_value+'\n')
262260

263-
logging.info("Exporting variable: %s=%s", var_name, var_value)
261+
logging.debug("Exporting variable: %s=%s", var_name, var_value)
264262

265263
##############################################################
266264

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
query ApplicationsStatusesQuery(
2-
$runtime: String!
3-
$name: String!
4-
$namespace: String
5-
) {
6-
application(runtime: $runtime, name: $name, namespace: $namespace) {
1+
query appstatus ($name: String!) {
2+
applicationProxyQuery(
3+
name: $name
4+
){
75
metadata {
8-
runtime
96
name
10-
namespace
11-
cluster
12-
__typename
137
}
14-
healthStatus
15-
syncStatus
16-
syncPolicy
8+
status {
9+
health {
10+
status
11+
}
12+
sync {
13+
status
14+
}
15+
}
1716
}
1817
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
query ApplicationsStatusesQuery(
2+
$runtime: String!
3+
$name: String!
4+
$namespace: String
5+
) {
6+
application(runtime: $runtime, name: $name, namespace: $namespace) {
7+
metadata {
8+
runtime
9+
name
10+
namespace
11+
cluster
12+
__typename
13+
}
14+
healthStatus
15+
syncStatus
16+
syncPolicy
17+
}
18+
}

incubating/argo-cd-sync/step.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
kind: step-type
22
metadata:
33
name: argo-cd-sync
4-
version: 1.4.1
4+
version: 1.4.2
55
isPublic: true
66
description: Syncs Argo CD apps managed by our GitOps Runtimes
77
sources:
@@ -120,7 +120,7 @@ spec:
120120
},
121121
"IMAGE_TAG": {
122122
"type": "string",
123-
"default": "1.3.1",
123+
"default": "1.4.2",
124124
"description": "OPTIONAL - To overwrite the tag to use"
125125
}
126126
}

0 commit comments

Comments
 (0)