Skip to content

argocd integration: applications resync fails with TypeError when API returns {"items": null} for per-cluster queries #3022

@fijimunkii

Description

@fijimunkii

Summary

The ArgoCD integration fails to sync argocdApplication and argocdDeploymentHistory kinds with TypeError: 'NoneType' object is not iterable. The root cause is that the integration queries /api/v1/applications?cluster=<cluster-name> but the ArgoCD API returns {"items": null} for that filter — it does not support filtering by cluster name via the cluster query parameter.

Versions

  • Integration: 0.2.27 and 0.2.28 (reproduced on both)
  • Ocean: 0.38.21 and 0.38.22
  • ArgoCD: standard install, multiple external clusters registered

Error

TypeError: 'NoneType' object is not iterable

Traceback (most recent call last):
  File "/app/.venv/lib/python3.13/site-packages/port_ocean/core/integrations/mixins/utils.py", line 178, in resync_generator_wrapper
    result = validate_result(await anext(generator))
  File "/app/main.py", line 27, in on_resources_resync
    async for cluster in argocd_client.get_resources_for_available_clusters(
  File "/app/client.py", line 191, in get_resources_for_available_clusters
    async for resources in stream_async_iterators_tasks(*tasks):
  File "/app/client.py", line 120, in get_paginated_resources
    self._handle_error(e, url, params=params)
  File "/app/client.py", line 148, in _handle_error
    raise exception
  File "/app/client.py", line 108, in get_paginated_resources
    for batch in batched(response_data.get("items", []), PAGE_SIZE):
TypeError: 'NoneType' object is not iterable

The integration logs show 2 failures (one for argocdApplication, one for argocdDeploymentHistory) and the entire resync is aborted:

Resync failed with 2 errors, skipping delete phase due to incomplete state

Root Cause

The ArgoCD REST API returns {"metadata": {...}, "items": null} when the ?cluster=<name> query parameter is used — it does not support filtering by cluster name via this parameter, and returns null items rather than an error or empty list.

Verified directly against the ArgoCD API from inside the integration pod:

# Filter by cluster NAME — returns null items
curl -H "Authorization: Bearer $TOKEN" \
  "http://argocd-server.argocd.svc.cluster.local/api/v1/applications?cluster=ss-n-inf-admin-gke"
# → {"metadata":{},"items":null}

# Filter by server URL — works correctly
curl -H "Authorization: Bearer $TOKEN" \
  "http://argocd-server.argocd.svc.cluster.local/api/v1/applications?server=https://gke-fff46c43...gke.goog"
# → {"metadata":{},"items":[...]}

# No filter — also works
curl -H "Authorization: Bearer $TOKEN" \
  "http://argocd-server.argocd.svc.cluster.local/api/v1/applications"
# → {"metadata":{},"items":[...]}  (51 apps)

The cluster and project kinds sync successfully (0 errors). Only the application kind fails.

Fix

In client.py, get_resources_for_available_clusters (line ~191) should pass the cluster's server URL as the server query parameter instead of (or in addition to) the cluster name. For example:

# Wrong — ArgoCD returns {"items": null} for this
params["cluster"] = cluster.name

# Correct — ArgoCD returns items for this
params["server"] = cluster.server

Additionally, line 108 should guard against an explicitly-null items value regardless, since .get("items", []) only falls back to [] when the key is absent, not when the value is null:

# Current — crashes when items is explicitly null
for batch in batched(response_data.get("items", []), PAGE_SIZE):

# Safer
for batch in batched(response_data.get("items") or [], PAGE_SIZE):

Impact

All argocdApplication and argocdDeploymentHistory entities stop syncing. The resync is aborted and the delete phase is skipped, leaving stale data in Port.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions