Skip to content

Commit

Permalink
v1.4.4: prevent sync operation for app in auto-sync mode
Browse files Browse the repository at this point in the history
Signed-off-by: Laurent Rochette <[email protected]>
  • Loading branch information
lrochette committed Mar 6, 2024
1 parent 0e787b6 commit 961a2d9
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 13 deletions.
4 changes: 4 additions & 0 deletions incubating/argo-cd-sync/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [1.4.4] - 2024-03-06
### Fixed
Do not sync an application in auto-sync mode

## [1.4.3] - 2024-02-22
### Fixed
intercepting application not found for better error message
Expand Down
42 changes: 31 additions & 11 deletions incubating/argo-cd-sync/argocd_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ def main():
export_variable(CF_OUTPUT_URL_VAR, link_to_app)

ingress_host = get_runtime_ingress_host()
execute_argocd_sync(ingress_host)
if application_autosync(ingress_host) == False:
execute_argocd_sync(ingress_host)
else:
logging.info("Skipping synchronization as Application is in auto-sync mode")

namespace = get_runtime_ns()
health, sync = get_app_status(ingress_host)

Expand Down Expand Up @@ -253,7 +257,7 @@ def execute_argocd_sync(ingress_host):
retries=3,
)
client = Client(transport=transport, fetch_schema_from_transport=False)
query = get_query('argocd_sync') ## gets gql query
query = get_query('argocd_sync') ## gets gql query
variables = {
"applicationName": APPLICATION,
"options": {
Expand All @@ -273,16 +277,32 @@ def execute_argocd_sync(ingress_host):
print(f"ERROR: cannot sync Application {APPLICATION}")
logging.debug("Syncing App result: %s", err)
sys.exit(1)
# finally:
# print("finally block")
# logging.debug("Syncing App result: %s", result)
# if result.errors[0].message.contains("NOT_FOUND_ERROR"):
# printf("Application %s does not exit")
#
# else:
# # Application sync'ed properly
# logging.debug("Syncing App result: %s", result)

def application_autosync(ingress_host):
runtime_api_endpoint = ingress_host + '/app-proxy/api/graphql'
transport = RequestsHTTPTransport(
url=runtime_api_endpoint,
headers={'authorization': CF_API_KEY},
verify=VERIFY,
retries=3,
)
client = Client(transport=transport, fetch_schema_from_transport=False)
query = get_query('get_app_autosync') ## gets gql query
variables = {
"applicationName": APPLICATION
}
try:
result = client.execute(query, variable_values=variables)
except Exception as err:
print(f"ERROR: cannot get sync policy from Application {APPLICATION}")
logging.debug("Application Sync policy result: %s", err)
sys.exit(1)

logging.debug("App sync Policy: ", result['applicationProxyQuery']['spec']['syncPolicy']['automated'])
if result['applicationProxyQuery']['spec']['syncPolicy']['automated'] == None:
return False
else:
return True

def export_variable(var_name, var_value):
path = os.getenv('CF_VOLUME_PATH') if os.getenv('CF_VOLUME_PATH') != None else './'
Expand Down
17 changes: 17 additions & 0 deletions incubating/argo-cd-sync/queries/get_app_autosync.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
query appsyncstatus ($applicationName: String!) {

applicationProxyQuery(
name: $applicationName
){
metadata {
name
}
spec {
syncPolicy {
automated {
prune
}
}
}
}
}
4 changes: 2 additions & 2 deletions incubating/argo-cd-sync/step.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
kind: step-type
metadata:
name: argo-cd-sync
version: 1.4.3
version: 1.4.4
isPublic: true
description: Syncs Argo CD apps managed by our GitOps Runtimes
sources:
Expand Down Expand Up @@ -120,7 +120,7 @@ spec:
},
"IMAGE_TAG": {
"type": "string",
"default": "1.4.3",
"default": "1.4.4",
"description": "OPTIONAL - To overwrite the tag to use"
}
}
Expand Down

0 comments on commit 961a2d9

Please sign in to comment.