From 5d1addcc0c3d5b1ddf4becc04e7404a99498a9d3 Mon Sep 17 00:00:00 2001 From: Bohdan Pysarenko Date: Tue, 28 Jan 2025 16:29:51 +0200 Subject: [PATCH 1/5] add new option --- graduated/gitops-argocd-sync/CHANGELOG.md | 3 +++ graduated/gitops-argocd-sync/README.md | 1 + graduated/gitops-argocd-sync/argocd_sync.py | 25 +++++++++++-------- .../queries/argocd_sync.graphql | 4 +-- .../queries/get_app_autosync.graphql | 5 ++-- .../queries/get_app_existence.graphql | 5 ++-- .../queries/get_app_status.graphql | 5 ++-- .../queries/get_app_status.orig.graphql | 4 +-- graduated/gitops-argocd-sync/step.yaml | 7 +++++- 9 files changed, 38 insertions(+), 21 deletions(-) diff --git a/graduated/gitops-argocd-sync/CHANGELOG.md b/graduated/gitops-argocd-sync/CHANGELOG.md index 84469f41c..8e7a03f45 100644 --- a/graduated/gitops-argocd-sync/CHANGELOG.md +++ b/graduated/gitops-argocd-sync/CHANGELOG.md @@ -1,4 +1,7 @@ # Changelog +## [1.4.6] - 2025-01-28 +### Changed +- Add APP_NAMESPACE option ## [1.4.5] - 2024-04-04 ### Fixed diff --git a/graduated/gitops-argocd-sync/README.md b/graduated/gitops-argocd-sync/README.md index a39b2abc4..b2e95205b 100644 --- a/graduated/gitops-argocd-sync/README.md +++ b/graduated/gitops-argocd-sync/README.md @@ -15,6 +15,7 @@ Syncs Argo CD apps managed by our GitOps Runtimes using Codefresh API |:---------------|:------------------------------------------------------------------------------------------|:---------|:--------------------------------------------| | RUNTIME | The name of the GitOps Runtime managing the Argo CD Application | false | | | APPLICATION | The name of the Argo CD Application to be synced | false | | +| APP_NAMESPACE | The namespace of the Argo CD Application to be synced | true | | | ROLLBACK | Initiate a rollback to the previous revision if the Sync and Wait does not become healthy | true | | | WAIT_ROLLBACK | Wait for the app to be healthy after a rollback. Forces ROLLBACK to true | true | | | CA_BUNDLE | A base64 encoded string that contain the complete CA Certificate Bundle | true | | diff --git a/graduated/gitops-argocd-sync/argocd_sync.py b/graduated/gitops-argocd-sync/argocd_sync.py index c34e3a583..28efc3a8e 100644 --- a/graduated/gitops-argocd-sync/argocd_sync.py +++ b/graduated/gitops-argocd-sync/argocd_sync.py @@ -12,6 +12,14 @@ RUNTIME = os.getenv('RUNTIME') APPLICATION = os.getenv('APPLICATION') +APP_NAMESPACE = os.getenv('APP_NAMESPACE') + +APP_DICTIONARY = { + "applicationName": APPLICATION, +} +if APP_NAMESPACE is not None: + APP_DICTIONARY["applicationNamespace"] = APP_NAMESPACE + # Wait and Rollback options WAIT_HEALTHY = True if os.getenv('WAIT_HEALTHY', "false").lower() == "true" else False @@ -43,6 +51,7 @@ def main(): logging.debug("RUNTIME: %s", RUNTIME) logging.debug("APPLICATION: %s", APPLICATION) + logging.debug("NAMESPACE: %s", NAMESPACE) logging.debug("WAIT: %s", WAIT_HEALTHY) logging.debug("INTERVAL: %d", INTERVAL) logging.debug("MAX CHECKS: %s", MAX_CHECKS) @@ -214,9 +223,7 @@ def get_app_status(ingress_host): ) client = Client(transport=transport, fetch_schema_from_transport=False) query = get_query('get_app_status') ## gets gql query - variables = { - "name": APPLICATION - } + variables = {**APP_DICTIONARY} result = client.execute(query, variable_values=variables) logging.debug("App Status result: %s", result) @@ -276,12 +283,14 @@ def execute_argocd_sync(ingress_host): ) client = Client(transport=transport, fetch_schema_from_transport=False) query = get_query('argocd_sync') ## gets gql query + variables = { - "applicationName": APPLICATION, + **APP_DICTIONARY, "options": { "prune": True } } + try: result = client.execute(query, variable_values=variables) except TransportQueryError as err: @@ -312,9 +321,7 @@ def application_exist(ingress_host): ) client = Client(transport=transport, fetch_schema_from_transport=False) query = get_query('get_app_existence') ## gets gql query - variables = { - "applicationName": APPLICATION - } + variables = {**APP_DICTIONARY} try: result = client.execute(query, variable_values=variables) except TransportQueryError as err: @@ -346,9 +353,7 @@ def application_autosync(ingress_host): ) client = Client(transport=transport, fetch_schema_from_transport=False) query = get_query('get_app_autosync') ## gets gql query - variables = { - "applicationName": APPLICATION - } + variables = {**APP_DICTIONARY} try: result = client.execute(query, variable_values=variables) except Exception as err: diff --git a/graduated/gitops-argocd-sync/queries/argocd_sync.graphql b/graduated/gitops-argocd-sync/queries/argocd_sync.graphql index 91538460a..c9edc62b3 100644 --- a/graduated/gitops-argocd-sync/queries/argocd_sync.graphql +++ b/graduated/gitops-argocd-sync/queries/argocd_sync.graphql @@ -1,5 +1,5 @@ -query sync($applicationName: String!, $options: SyncOptions) { - sync(applicationName: $applicationName, options: $options) { +query sync($applicationName: String!, $options: SyncOptions, $applicationNamespace: String) { + sync(applicationName: $applicationName, options: $options, appNamespace: $applicationNamespace) { metadata { name __typename diff --git a/graduated/gitops-argocd-sync/queries/get_app_autosync.graphql b/graduated/gitops-argocd-sync/queries/get_app_autosync.graphql index df21f0180..0bd5903f0 100644 --- a/graduated/gitops-argocd-sync/queries/get_app_autosync.graphql +++ b/graduated/gitops-argocd-sync/queries/get_app_autosync.graphql @@ -1,7 +1,8 @@ -query appsyncstatus ($applicationName: String!) { +query appsyncstatus ($applicationName: String!, $applicationNamespace: String) { applicationProxyQuery( - name: $applicationName + name: $applicationName, + appNamespace: $applicationNamespace ){ metadata { name diff --git a/graduated/gitops-argocd-sync/queries/get_app_existence.graphql b/graduated/gitops-argocd-sync/queries/get_app_existence.graphql index dd173051e..13f5b3305 100644 --- a/graduated/gitops-argocd-sync/queries/get_app_existence.graphql +++ b/graduated/gitops-argocd-sync/queries/get_app_existence.graphql @@ -1,6 +1,7 @@ -query appexistence ($applicationName: String!) { +query appexistence ($applicationName: String!, $applicationNamespace: String) { applicationProxyQuery( - name: $applicationName + name: $applicationName, + appNamespace: $applicationNamespace ){ metadata { name diff --git a/graduated/gitops-argocd-sync/queries/get_app_status.graphql b/graduated/gitops-argocd-sync/queries/get_app_status.graphql index 574b0d645..9d470143e 100644 --- a/graduated/gitops-argocd-sync/queries/get_app_status.graphql +++ b/graduated/gitops-argocd-sync/queries/get_app_status.graphql @@ -1,6 +1,7 @@ -query appstatus ($name: String!) { +query appstatus ($name: String!, $applicationNamespace: String) { applicationProxyQuery( - name: $name + name: $name, + appNamespace: $applicationNamespace ){ metadata { name diff --git a/graduated/gitops-argocd-sync/queries/get_app_status.orig.graphql b/graduated/gitops-argocd-sync/queries/get_app_status.orig.graphql index 796f42dd4..275a577d1 100644 --- a/graduated/gitops-argocd-sync/queries/get_app_status.orig.graphql +++ b/graduated/gitops-argocd-sync/queries/get_app_status.orig.graphql @@ -1,9 +1,9 @@ query ApplicationsStatusesQuery( $runtime: String! $name: String! - $namespace: String + $applicationNamespace: String ) { - application(runtime: $runtime, name: $name, namespace: $namespace) { + application(runtime: $runtime, name: $name, namespace: $applicationNamespace) { metadata { runtime name diff --git a/graduated/gitops-argocd-sync/step.yaml b/graduated/gitops-argocd-sync/step.yaml index 0ded3d0d4..dc928c1d0 100644 --- a/graduated/gitops-argocd-sync/step.yaml +++ b/graduated/gitops-argocd-sync/step.yaml @@ -1,7 +1,7 @@ kind: step-type metadata: name: gitops-argocd-sync - version: 1.4.5 + version: 1.4.6 isPublic: true description: Syncs Argo CD apps managed by our GitOps Runtimes sources: @@ -48,6 +48,7 @@ metadata: arguments: RUNTIME: my-runtime APPLICATION: my-app + APP_NAMESPACE: my-app-sync WAIT_HEALTHY: true INTERVAL: 60 MAX_CHECKS: 3 @@ -74,6 +75,10 @@ spec: "type": "string", "description": "The name of the Argo CD Application to be synced" }, + "APP_NAMESPACE": { + "type": "string", + "description": "The namespace of the Argo CD Application to be synced" + }, "WAIT_HEALTHY": { "type": "boolean", "description": "OPTIONAL - Wait for the app to be healthy", From 2ece57488d1a5c53bd61b82bb5541bba553243cb Mon Sep 17 00:00:00 2001 From: Bohdan Pysarenko Date: Tue, 28 Jan 2025 16:35:55 +0200 Subject: [PATCH 2/5] fix --- .../gitops-argocd-sync/queries/get_app_status.orig.graphql | 4 ++-- graduated/gitops-argocd-sync/step.yaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/graduated/gitops-argocd-sync/queries/get_app_status.orig.graphql b/graduated/gitops-argocd-sync/queries/get_app_status.orig.graphql index 275a577d1..796f42dd4 100644 --- a/graduated/gitops-argocd-sync/queries/get_app_status.orig.graphql +++ b/graduated/gitops-argocd-sync/queries/get_app_status.orig.graphql @@ -1,9 +1,9 @@ query ApplicationsStatusesQuery( $runtime: String! $name: String! - $applicationNamespace: String + $namespace: String ) { - application(runtime: $runtime, name: $name, namespace: $applicationNamespace) { + application(runtime: $runtime, name: $name, namespace: $namespace) { metadata { runtime name diff --git a/graduated/gitops-argocd-sync/step.yaml b/graduated/gitops-argocd-sync/step.yaml index dc928c1d0..5427f82e6 100644 --- a/graduated/gitops-argocd-sync/step.yaml +++ b/graduated/gitops-argocd-sync/step.yaml @@ -48,7 +48,7 @@ metadata: arguments: RUNTIME: my-runtime APPLICATION: my-app - APP_NAMESPACE: my-app-sync + APP_NAMESPACE: my-app-ns WAIT_HEALTHY: true INTERVAL: 60 MAX_CHECKS: 3 From 1b485910f878994b9944704674f40f48132574c3 Mon Sep 17 00:00:00 2001 From: Bohdan Pysarenko Date: Tue, 28 Jan 2025 21:36:06 +0200 Subject: [PATCH 3/5] upd version --- graduated/gitops-argocd-sync/step.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graduated/gitops-argocd-sync/step.yaml b/graduated/gitops-argocd-sync/step.yaml index 5427f82e6..1a818d700 100644 --- a/graduated/gitops-argocd-sync/step.yaml +++ b/graduated/gitops-argocd-sync/step.yaml @@ -1,7 +1,7 @@ kind: step-type metadata: name: gitops-argocd-sync - version: 1.4.6 + version: 1.5.0 isPublic: true description: Syncs Argo CD apps managed by our GitOps Runtimes sources: From 48ad25e1633017a4983f003611153f65e6067f1c Mon Sep 17 00:00:00 2001 From: Bohdan Pysarenko Date: Tue, 28 Jan 2025 21:39:15 +0200 Subject: [PATCH 4/5] fix --- graduated/gitops-argocd-sync/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graduated/gitops-argocd-sync/CHANGELOG.md b/graduated/gitops-argocd-sync/CHANGELOG.md index 8e7a03f45..9fa9b77dd 100644 --- a/graduated/gitops-argocd-sync/CHANGELOG.md +++ b/graduated/gitops-argocd-sync/CHANGELOG.md @@ -1,5 +1,5 @@ # Changelog -## [1.4.6] - 2025-01-28 +## [1.5.0] - 2025-01-29 ### Changed - Add APP_NAMESPACE option From a38bbface85a64f3a4089809daea9c4aa76ebecd Mon Sep 17 00:00:00 2001 From: Bohdan Pysarenko Date: Wed, 29 Jan 2025 12:14:04 +0200 Subject: [PATCH 5/5] add back compatability info --- graduated/gitops-argocd-sync/CHANGELOG.md | 2 +- graduated/gitops-argocd-sync/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/graduated/gitops-argocd-sync/CHANGELOG.md b/graduated/gitops-argocd-sync/CHANGELOG.md index 9fa9b77dd..867867a20 100644 --- a/graduated/gitops-argocd-sync/CHANGELOG.md +++ b/graduated/gitops-argocd-sync/CHANGELOG.md @@ -1,7 +1,7 @@ # Changelog ## [1.5.0] - 2025-01-29 ### Changed -- Add APP_NAMESPACE option +- Add APP_NAMESPACE option (supported from app-proxy v1.2600.1) ## [1.4.5] - 2024-04-04 ### Fixed diff --git a/graduated/gitops-argocd-sync/README.md b/graduated/gitops-argocd-sync/README.md index b2e95205b..cb30f5184 100644 --- a/graduated/gitops-argocd-sync/README.md +++ b/graduated/gitops-argocd-sync/README.md @@ -15,7 +15,7 @@ Syncs Argo CD apps managed by our GitOps Runtimes using Codefresh API |:---------------|:------------------------------------------------------------------------------------------|:---------|:--------------------------------------------| | RUNTIME | The name of the GitOps Runtime managing the Argo CD Application | false | | | APPLICATION | The name of the Argo CD Application to be synced | false | | -| APP_NAMESPACE | The namespace of the Argo CD Application to be synced | true | | +| APP_NAMESPACE | The namespace of the Argo CD Application to be synced, supported from app-proxy v1.2600.1 | true | | | ROLLBACK | Initiate a rollback to the previous revision if the Sync and Wait does not become healthy | true | | | WAIT_ROLLBACK | Wait for the app to be healthy after a rollback. Forces ROLLBACK to true | true | | | CA_BUNDLE | A base64 encoded string that contain the complete CA Certificate Bundle | true | |