Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions graduated/gitops-argocd-sync/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Changelog
## [1.4.6] - 2025-01-28
### Changed
- Add APP_NAMESPACE option

## [1.4.5] - 2024-04-04
### Fixed
Expand Down
1 change: 1 addition & 0 deletions graduated/gitops-argocd-sync/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | |
Expand Down
25 changes: 15 additions & 10 deletions graduated/gitops-argocd-sync/argocd_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions graduated/gitops-argocd-sync/queries/argocd_sync.graphql
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 3 additions & 2 deletions graduated/gitops-argocd-sync/queries/get_app_autosync.graphql
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
query appsyncstatus ($applicationName: String!) {
query appsyncstatus ($applicationName: String!, $applicationNamespace: String) {

applicationProxyQuery(
name: $applicationName
name: $applicationName,
appNamespace: $applicationNamespace
){
metadata {
name
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
query appexistence ($applicationName: String!) {
query appexistence ($applicationName: String!, $applicationNamespace: String) {
applicationProxyQuery(
name: $applicationName
name: $applicationName,
appNamespace: $applicationNamespace
){
metadata {
name
Expand Down
5 changes: 3 additions & 2 deletions graduated/gitops-argocd-sync/queries/get_app_status.graphql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
query appstatus ($name: String!) {
query appstatus ($name: String!, $applicationNamespace: String) {
applicationProxyQuery(
name: $name
name: $name,
appNamespace: $applicationNamespace
){
metadata {
name
Expand Down
7 changes: 6 additions & 1 deletion graduated/gitops-argocd-sync/step.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
kind: step-type
metadata:
name: gitops-argocd-sync
version: 1.4.5
version: 1.4.6
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pysarenko-bohdan let's bump minor, it's a new feature

Suggested change
version: 1.4.6
version: 1.5.0

isPublic: true
description: Syncs Argo CD apps managed by our GitOps Runtimes
sources:
Expand Down Expand Up @@ -48,6 +48,7 @@ metadata:
arguments:
RUNTIME: my-runtime
APPLICATION: my-app
APP_NAMESPACE: my-app-ns
WAIT_HEALTHY: true
INTERVAL: 60
MAX_CHECKS: 3
Expand All @@ -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",
Expand Down
Loading